0

I have the default PATH variable as set in the .zshrc file.

I am looking for an elegant and simple way to add more directories to the PATH per different profiles in iTerm2.

What would be the best way to do it?

To be concrete, assume I want:

  1. Add /Users/myusername/somfolder1 and /Users/myusername/somfolder2/bin to path of profile1.
  2. Add /Users/myusername/somfolder3 to profile2.
10
  • Why not set the path as a command when the profile is opened?
    – Allan
    Commented Jun 20, 2023 at 12:26
  • Why not just have one path with all the search locations in it? Commented Jun 20, 2023 at 14:55
  • @Allan, the whole idea is being time efficient. Commented Jun 20, 2023 at 17:04
  • @MarcWilson, Some are different versions of the same binaries, so they can not coexist. Commented Jun 20, 2023 at 17:05
  • 1
    export just makes the variable available in subshells. For now, just leave it off and see if the PATH get's set as you expect.
    – Allan
    Commented Jun 22, 2023 at 14:35

2 Answers 2

1

I use Terminal, not iTerm2, so I don't know if there is something comparable, but in Terminal, the following works for bash:

cat > ~/profileForThisTerm << EOF
PATH="${PATH}:/Users/myusername/somfolder1"

then

  • Settings
  • Profiles
  • Choose the profile to modify
  • Shell
  • Click Run command
  • Enter source ~/profileForThisTerm
  • Make sure Run inside shell is clicked

Opening a terminal window against that Terminal profile You might be able to find something similar for iTerm2 and zsh.

1
  • Basically create a script and run it. I will try. Commented Jun 20, 2023 at 17:05
0

If you're in a typical profile that starts your normal login shell, you can inspect the $ITERM_PROFILE environment variable at the start of your bash or zsh init.

So e.g., I have the following logic to abbreviate my init if I'm in an iTerm2 profile that's only going to run htop:

if [ -n "$ITERM_PROFILE" ];
then
    # check if we're using an iTerm2 profile that's non- or low-interactive
    # htop profiles should mostly be non-interactive
    if echo "$ITERM_PROFILE" | grep -q "^htop";
    then
        export ABBREVIATED_INIT=1;
    fi
fi

Inside that logic you can set/modify PATH or whatever other things you want.

You must log in to answer this question.

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