Skip to main content
added 25 characters in body
Source Link
nsg
  • 1.2k
  • 9
  • 11

You could use PROMPT_COMMAND, the code specified in PROMPT_COMMAND is executed before bash draws the prompt.

# Call function 'foo' PROMPT_COMMAND=foo # The function foo() { if [[ $PWD == "/home/$HOME"$HOME/repository/foo/"foo" ]]; then set_foo_env.sh fi } 

I'mNote, PROMPT_COMMAND is bash specific, and this is not 100% sure ifa efficient way because the environment variablesfunction foo will be correctly passed down tocalled every time bash draws the shellprompt.

Edit: it works

You could use PROMPT_COMMAND, the code specified in PROMPT_COMMAND is executed before bash draws the prompt.

# Call function 'foo' PROMPT_COMMAND=foo # The function foo() { if [[ $PWD == "/home/$HOME/repository/foo/" ]]; then set_foo_env.sh fi } 

I'm not 100% sure if the environment variables will be correctly passed down to the shell.

Edit: it works

You could use PROMPT_COMMAND, the code specified in PROMPT_COMMAND is executed before bash draws the prompt.

# Call function 'foo' PROMPT_COMMAND=foo # The function foo() { if [[ $PWD == "$HOME/repository/foo" ]]; then set_foo_env.sh fi } 

Note, PROMPT_COMMAND is bash specific, and this is not a efficient way because the function foo will be called every time bash draws the prompt.

Source Link
nsg
  • 1.2k
  • 9
  • 11

You could use PROMPT_COMMAND, the code specified in PROMPT_COMMAND is executed before bash draws the prompt.

# Call function 'foo' PROMPT_COMMAND=foo # The function foo() { if [[ $PWD == "/home/$HOME/repository/foo/" ]]; then set_foo_env.sh fi } 

I'm not 100% sure if the environment variables will be correctly passed down to the shell.

Edit: it works