Let's say I have a "Work" profile in iTerm2 and want to set a different HISTFILE for this profile, called .zsh_history_work, so that I don't see my work commands showing up in my regular profiles.

I know that it's possible for me to switch to the different HISTFILE by writing HISTFILE=~/.zsh_history_work every time I open a new window with the "Work" profile. Is there a way to make this automatically happen so that I don't need to run the command all the time?

1 Answer 1


To do this, go to iTerm2 Preferences > Profiles > [Select "Work" Profile] > General > Command > Send text at start, and enter the following:


This should work as long as you're not using oh-my-zsh. If you are, the HISTFILE is loaded during the .zshrc startup. This will cause commands to be written to the proper "work" history file, but read from the regular ~/.zsh_history file. To combat this, we use a different command:

fc -p ~/.zsh_history_work

This will allow you to both read and write from the work history file.

One more thing: this command will show up every time you open a window or tab with the Work profile. To prevent this from happening, type the following instead:

fc -p ~/.zsh_history_work && clear

This will automatically clear the page so that you're left with a blank terminal with your desired history file!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .