3 # bash_prompt; adapted from
4 # https://github.com/necolas/dotfiles/blob/master/shell/bash_prompt and
5 # http://vitus-wagner.livejournal.com/1176589.html?thread=40146189#t40146189
11 # check if the current directory is in a git repository
12 if [ $(git rev-parse --is-inside-work-tree &>/dev/null; printf "%s" $?) == 0 ]; then
14 # check if the current directory is in .git before running git checks
15 if [ "$(git rev-parse --is-inside-git-dir 2> /dev/null)" == "false" ]; then
17 # ensure index is up to date
18 #git update-index --really-refresh -q &>/dev/null
20 # check for uncommitted changes in the index
21 if ! $(git diff --quiet --ignore-submodules --cached); then
25 # check for unstaged changes
26 if ! $(git diff-files --quiet --ignore-submodules --); then
30 # check for untracked files
31 if [ -n "$(git ls-files --others --exclude-standard)" ]; then
35 # check for stashed files
36 if $(git rev-parse --verify refs/stash &>/dev/null); then
42 # get the short symbolic ref
43 # if HEAD isn't a symbolic ref, get the short SHA
44 # otherwise, just give up
45 branchName="$(git symbolic-ref --quiet --short HEAD 2> /dev/null || \
46 git rev-parse --short HEAD 2> /dev/null || \
49 [ -n "$s" ] && s=" [$s]"
51 printf "%s" "$1$branchName$s"
88 if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
89 tput sgr0 # reset colors
99 orange=$(tput setaf 3)
100 magenta=$(tput setaf 5)
102 white=$bold$(tput setaf 7)
103 yellow=$(tput setaf 3)
109 dim_orange=$dim$orange
110 dim_magenta=$dim$magenta
113 dim_yellow=$dim$yellow
133 dim_orange="\e[1;33m"
134 dim_magenta="\e[1;35m"
137 dim_yellow="\e[1;33m"
140 charStyle="$reset$bold$black"
141 gitStyle="\[$white\]on \[$magenta\]"
142 case "$BACKGROUND" in
144 hostStyle="$reset$cyan"
147 hostStyle="$reset$blue"
150 wdirStyle="$reset$green"
154 if [[ "$USER" == "root" ]]; then
155 userStyle="$bold$red"
161 # display the user, host and current working directory in the terminal title
163 *rxvt*|screen*|*term*|vt100)
164 PS1="\[\033]0;\u@\h:\w\007\]"
167 PS1+"\[\033k\u@\h:\w\033\\\]" # Set screen/tmux caption
178 PS1+="\[$userStyle\]\u" # username
179 PS1+="\[$charStyle\]@"
180 PS1+="\[$hostStyle\]\h " # host
181 #PS1+="\[$charStyle\]: "
182 PS1+="\[$wdirStyle\]\W " # working directory
183 PS1+='`erco=$?; [ $erco == 0 ] && echo -n ":)" || echo -n '"\"\[$red\]:(\[$reset\] $\""'?=$erco` '
184 PS1+="\$(prompt_git \"$gitStyle\")" # git repository details
186 PS1+="\[$charStyle\]\$ \[$reset\]" # $ (and reset color)