Skip to main content
replaced http://unix.stackexchange.com/ with https://unix.stackexchange.com/
Source Link

Change the cd into a function to run the real cd and run your script afterward.

cd () { if builtin cd ${1:+"$@"} && [ -r ./set_foo_env.sh ]; then . ./set_foo_env.sh fi } 

This assumes that:

  1. The set_foo_env.sh would be specific to a single directories, and
  2. That set_foo_env.sh should change the existing shell's environment.

If you want path-based with a global file, then look at the question that manatwork mentioned ( Execute bash scripts on entering a directoryExecute bash scripts on entering a directory).

Change the cd into a function to run the real cd and run your script afterward.

cd () { if builtin cd ${1:+"$@"} && [ -r ./set_foo_env.sh ]; then . ./set_foo_env.sh fi } 

This assumes that:

  1. The set_foo_env.sh would be specific to a single directories, and
  2. That set_foo_env.sh should change the existing shell's environment.

If you want path-based with a global file, then look at the question that manatwork mentioned ( Execute bash scripts on entering a directory).

Change the cd into a function to run the real cd and run your script afterward.

cd () { if builtin cd ${1:+"$@"} && [ -r ./set_foo_env.sh ]; then . ./set_foo_env.sh fi } 

This assumes that:

  1. The set_foo_env.sh would be specific to a single directories, and
  2. That set_foo_env.sh should change the existing shell's environment.

If you want path-based with a global file, then look at the question that manatwork mentioned ( Execute bash scripts on entering a directory).

added 2 characters in body
Source Link
jw013
  • 53k
  • 11
  • 143
  • 142

Change the cd into a function to run the real cd and run your script afterward.

cd () { if builtin cd ${1:+"$@"} && [ -r ./set_foo_env.sh ]; then . ./set_foo_env.sh fi } 

This assumes that:

  1. The set_foo_env.sh would be specific to a single directories, and
  2. That set_foo_env.sh should change the existing shell's environment.

If you want path-based with a global file, then look at the question that manatwork mentioned ( Execute bash scripts on entering a directory).

Change the cd into a function to run the real cd and run your script afterward.

cd () { if builtin cd ${1:+"$@"} && [ -r ./set_foo_env.sh ]; then . set_foo_env.sh fi } 

This assumes that:

  1. The set_foo_env.sh would be specific to a single directories, and
  2. That set_foo_env.sh should change the existing shell's environment.

If you want path-based with a global file, then look at the question that manatwork mentioned ( Execute bash scripts on entering a directory).

Change the cd into a function to run the real cd and run your script afterward.

cd () { if builtin cd ${1:+"$@"} && [ -r ./set_foo_env.sh ]; then . ./set_foo_env.sh fi } 

This assumes that:

  1. The set_foo_env.sh would be specific to a single directories, and
  2. That set_foo_env.sh should change the existing shell's environment.

If you want path-based with a global file, then look at the question that manatwork mentioned ( Execute bash scripts on entering a directory).

Source Link
Arcege
  • 22.9k
  • 5
  • 58
  • 65

Change the cd into a function to run the real cd and run your script afterward.

cd () { if builtin cd ${1:+"$@"} && [ -r ./set_foo_env.sh ]; then . set_foo_env.sh fi } 

This assumes that:

  1. The set_foo_env.sh would be specific to a single directories, and
  2. That set_foo_env.sh should change the existing shell's environment.

If you want path-based with a global file, then look at the question that manatwork mentioned ( Execute bash scripts on entering a directory).