Created
January 18, 2017 17:18
-
-
Save acobster/e830b261c3cc26786a90448fb9ef3dd9 to your computer and use it in GitHub Desktop.
Customize bash prompt based on current cwd/environment
This file contains hidden or 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
# You want your prompt to warn you if you are in the directory tree of a production environment. | |
# Set the `LIVE_DIRS` array to the list of whatever directories should be considered production, | |
# and your prompt will contain a big, red "[PRODUCTION]" whenever you're in one of those directories, | |
# or a subdirectory thereof. | |
# Customize this variable | |
LIVE_DIRS=(/var/www/example.com /var/www/example2.com) | |
cwdEnvironment() { | |
local _live | |
_live='' | |
for d in "${LIVE_DIRS[@]}" ; do | |
if [[ `pwd` =~ ^"$d".*$ ]] ; then | |
_live=' [PRODUCTION]' | |
fi | |
done | |
printf -- '%s' "$_live" | |
return 0 | |
} | |
# The important part here is the `\[$(tput bold 1)\]\e[0:31m$(cwdEnvironment)\e[m\[$(tput sgr0)\]` - that's the bold, red part | |
export PS1='[\u@\h \W]\[$(tput bold 1)\]\e[0:31m$(cwdEnvironment)\e[m\[$(tput sgr0)\] \$ ' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment