Skip to content

Instantly share code, notes, and snippets.

@danman01
Created March 21, 2017 01:38
Show Gist options
  • Save danman01/a10b18be0bb1f96ebf0433e91272de0d to your computer and use it in GitHub Desktop.
Save danman01/a10b18be0bb1f96ebf0433e91272de0d to your computer and use it in GitHub Desktop.
bash_prompt_customization.sh
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
parse_git_dirty() {
st=$(git status 2>/dev/null | tail -n 1)
if [[ $st == "" ]]; then
echo ''
elif [[ $st == "nothing to commit (working directory clean)" ]]; then
echo ''
elif [[ $st == 'nothing added to commit but untracked files present (use "git add" to track)' ]]; then
echo '?'
else
echo '*'
fi
}
# coloring the terminal comman line
SB_GREEN="\[\033[1;32m\]"
SB_BLUE="\[\033[1;34m\]"
SB_RED="\[\033[1;31m\]"
SB_NOCOLOR="\[\033[0m\]"
# customization of bash prompt:
# small \w gives full path. small \h gives network address (first octet)
export PS1="$SB_GREEN\u@\H$SB_NOCOLOR: $SB_BLUE\W$SB_GREEN\$(parse_git_branch)$SB_RED\$(parse_git_dirty)$SB_NOCOLOR $ "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment