The project I work on has some executable scripts in the repository. These scripts are actually tools that automate some development tasks and I invoke them only when I’m inside the repo and they work only on files in the repo. My typical working session looks like this:
$ cd $REPO
$ ./tools/start-session
$ some-script some arguments
$ other-script other arguments
In other words, the start-session script just adds an appropriate entry to the $PATH variable.
I’d like to automate it further so that I don’t have to call the $REPO/tools/start-session script. What I’d like to achieve is to make bash automatically detect that I’m in my repo dir and append proper entry to $PATH. The point is that I have many working copies of my repo and the tools differ a bit in each branch, I move between working copies frequently and I’d like my shell to kind of guess which script I want to invoke.
How do I do that?
The only thing I can think of is that the $PS1 variable gets executed each time a command is completed, so I could somehow hook some $PATH-changing script in there using backticks, i.e. do some thing like
PS1=`update-path`$PS1
But this seems not the right way.
On the right track, but don’t use
PS1– you wantPROMPT_COMMAND. For example:will execute
lsevery time a new prompt appears. Whether this will solve you root problem I couldn’t say, as I’m not sure I understand it properly.