Skip to content

Instantly share code, notes, and snippets.

@ChrisHeerschap
Created March 19, 2015 19:53
Show Gist options
  • Save ChrisHeerschap/97f92474666b842b70d8 to your computer and use it in GitHub Desktop.
Save ChrisHeerschap/97f92474666b842b70d8 to your computer and use it in GitHub Desktop.
How to set prompt based on your current directory
PROMPT_COMMAND=$'
# Check if I have "/tmp/" in my current directory
if [[ $PWD == */tmp/* ]]
then
# Strip everything up to *tmp/
env=${PWD##*tmp/}
# Drop everything after the next /
env=${env%%/*}
# Set the PS1 with that env in the prompt, color coded
PS1=\'\[\e[33;44m\] * ${env} * \[\e[m\] [\u@\h] \W\\$ \'
else
# No /tmp/ in path, just set a standard prompt.
PS1=\'[\u@\h] \W\\$ \'
fi'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment