I would like to change PS1, but only if I am working in a particular directory. Is this possible, and how can I do this?
Asked
Active
Viewed 87 times
1 Answers
0
Yes this is possible. I have used PROMPT_COMMAND
to make this possible. This function is executed before any other command and is here where you can compare your current directory and make whatever you need. As you can see I am only checking the last path of the directory and just showing the apple logo if matches.
function __get_dir {
DIR=$(basename `pwd`)
if [[ $DIR == "desiredDir" ]]
then
LOGO=" "
else
LOGO=""
fi
}
PROMPT_COMMAND='__get_dir'
PS1="\W \u\[\033[0;33m\]\$(parse_git_branch_and_add_brackets) \$LOGO\[\033[0m\]\$ "

Pedro Fraca
- 185
- 9