blob: b7cbbf03fc3920796bd2e4c1502568c5d94e2bc2 [file] [log] [blame]
oddjobsman8c7b0792013-09-17 19:04:50 +05301# Sexy Bash Prompt, inspired by "Extravagant Zsh Prompt"
2# Screenshot: http://cloud.gf3.ca/M5rG
3# A big thanks to \amethyst on Freenode
4
5if [[ $COLORTERM = gnome-* && $TERM = xterm ]] && infocmp gnome-256color >/dev/null 2>&1; then export TERM=gnome-256color
6elif [[ $TERM != dumb ]] && infocmp xterm-256color >/dev/null 2>&1; then export TERM=xterm-256color
7fi
8
9if tput setaf 1 &> /dev/null; then
oddjobsman8c7b0792013-09-17 19:04:50 +053010 if [[ $(tput colors) -ge 256 ]] 2>/dev/null; then
11 MAGENTA=$(tput setaf 9)
12 ORANGE=$(tput setaf 172)
13 GREEN=$(tput setaf 190)
14 PURPLE=$(tput setaf 141)
15 WHITE=$(tput setaf 0)
16 else
17 MAGENTA=$(tput setaf 5)
18 ORANGE=$(tput setaf 4)
19 GREEN=$(tput setaf 2)
20 PURPLE=$(tput setaf 1)
21 WHITE=$(tput setaf 7)
22 fi
23 BOLD=$(tput bold)
24 RESET=$(tput sgr0)
25else
26 MAGENTA="\033[1;31m"
27 ORANGE="\033[1;33m"
28 GREEN="\033[1;32m"
29 PURPLE="\033[1;35m"
30 WHITE="\033[1;37m"
31 BOLD=""
32 RESET="\033[m"
33fi
34
35parse_git_dirty () {
36 [[ $(git status 2> /dev/null | tail -n1 | cut -c 1-17) != "nothing to commit" ]] && echo "*"
37}
38parse_git_branch () {
39 git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1$(parse_git_dirty)/"
40}
41
oddjobsmanfaa8b912013-11-28 00:07:29 +053042function prompt_command() {
43 PS1="\[${BOLD}${MAGENTA}\]\u \[$WHITE\]at \[$ORANGE\]\h \[$WHITE\]in \[$GREEN\]\w\[$WHITE\]\$([[ -n \$(git branch 2> /dev/null) ]] && echo \" on \")\[$PURPLE\]\$(parse_git_branch)\[$WHITE\]\n\$ \[$RESET\]"
44}
45
46PROMPT_COMMAND=prompt_command