Created
March 19, 2015 19:53
-
-
Save ChrisHeerschap/97f92474666b842b70d8 to your computer and use it in GitHub Desktop.
How to set prompt based on your current directory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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