Skip to content

Instantly share code, notes, and snippets.

@alexandre1985
Created July 5, 2020 20:15
Show Gist options
  • Save alexandre1985/a08670dae82387155095d1bbfdcbee5a to your computer and use it in GitHub Desktop.
Save alexandre1985/a08670dae82387155095d1bbfdcbee5a to your computer and use it in GitHub Desktop.
# Sexy Bash Prompt, inspired by "Extravagant Zsh Prompt"
# Screenshot: http://cloud.gf3.ca/M5rG
# A big thanks to \amethyst on Freenode
if [[ $COLORTERM = gnome-* && $TERM = xterm ]] && infocmp gnome-256color >/dev/null 2>&1; then
export TERM=gnome-256color
elif [[ $TERM != dumb ]] && infocmp xterm-256color >/dev/null 2>&1; then
export TERM=xterm-256color
fi
MAGENTA="\033[1;31m"
ORANGE="\033[1;33m"
GREEN="\033[1;32m"
PURPLE="\033[1;35m"
WHITE="\033[1;37m"
CYAN="\033[1;36m"
BLUE="\033[1;34m"
BLACK="\033[1;30m"
BOLD=""
RESET="\033[m"
function prompt_command() {
# if root user
if [ $(id -u) -eq 0 ]; then
# with cyan
PS1="\[${BOLD}${MAGENTA}\]\u \[$CYAN\]at \[$ORANGE\]\h \[$CYAN\]in \[$GREEN\]\w\[$CYAN\]\$([[ -n \$(git branch 2> /dev/null) ]] && echo \" on \")\[$PURPLE\]\$(parse_git_branch)\[$CYAN\]\n# \[$RESET\]"
else
# with cyan
PS1="\[${BOLD}${MAGENTA}\]\u \[$CYAN\]at \[$ORANGE\]\h \[$CYAN\]in \[$GREEN\]\w\[$CYAN\]\$([[ -n \$(git branch 2> /dev/null) ]] && echo \" on \")\[$PURPLE\]\$(parse_git_branch)\[$CYAN\]\n\$ \[$RESET\]"
fi
}
parse_git_dirty () {
[[ $(git status 2> /dev/null | tail -n1 | cut -c 1-17) != "nothing to commit" ]] && echo "*"
}
parse_git_branch () {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1$(parse_git_dirty)/"
}
prompt_command
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment