Skip to content

Instantly share code, notes, and snippets.

@revmischa
Last active October 27, 2017 20:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save revmischa/f5047d64e7cc78d681de48376868f7d8 to your computer and use it in GitHub Desktop.
Save revmischa/f5047d64e7cc78d681de48376868f7d8 to your computer and use it in GitHub Desktop.
European Bash Prompt ($PS1)
if [[ `whoami` == "root" ]]; then
ISROOT=1
fi
# Git branch in prompt.
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(❲.*\)/ ❲\1❳/'
}
# git status
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
}
USERPROMPT="$"
ROOTPROMPT="#"
LOCALTZ=`/bin/ls -l /etc/localtime 2>/dev/null|/usr/bin/cut -d"/" -f7,8 2>/dev/null`
if [[ -n "$LOCALTZ" && -z "${LOCALTZ##Europe*}" ]]; then
# in Europe
USERPROMPT="€"
ROOTPROMPT="£"
fi
# coloring the terminal command line
SB_GREEN="\[\033[1;32m\]"
SB_BLUE="\[\033[1;34m\]"
SB_RED="\[\033[1;31m\]"
SB_NOCOLOR="\[\033[0m\]"
USERATHOST="$SB_GREEN\u☭\h$SB_NOCOLOR: "
if [ $ISROOT ]; then
export PS1="${SB_GREEN}${USERATHOST}${SB_BLUE}\w${SB_NOCOLOR} $ROOTPROMPT "
else
export PS1="${SB_GREEN}${USERATHOST}${SB_BLUE}\w${SB_GREEN}\$(parse_git_branch)${SB_RED}\$(parse_git_dirty)${SB_NOCOLOR} $USERPROMPT "
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment