3 # bash_prompt; adapted from
4 # https://github.com/necolas/dotfiles/blob/master/shell/bash_prompt
10 # check if the current directory is in a git repository
11 if [ $(git rev-parse --is-inside-work-tree &>/dev/null; printf "%s" $?) == 0 ]; then
13 # check if the current directory is in .git before running git checks
14 if [ "$(git rev-parse --is-inside-git-dir 2> /dev/null)" == "false" ]; then
16 # ensure index is up to date
17 #git update-index --really-refresh -q &>/dev/null
19 # check for uncommitted changes in the index
20 if ! $(git diff --quiet --ignore-submodules --cached); then
24 # check for unstaged changes
25 if ! $(git diff-files --quiet --ignore-submodules --); then
29 # check for untracked files
30 if [ -n "$(git ls-files --others --exclude-standard)" ]; then
34 # check for stashed files
35 if $(git rev-parse --verify refs/stash &>/dev/null); then
41 # get the short symbolic ref
42 # if HEAD isn't a symbolic ref, get the short SHA
43 # otherwise, just give up
44 branchName="$(git symbolic-ref --quiet --short HEAD 2> /dev/null || \
45 git rev-parse --short HEAD 2> /dev/null || \
48 [ -n "$s" ] && s=" [$s]"
50 printf "%s" "$1$branchName$s"
87 if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
88 tput sgr0 # reset colors
98 orange=$(tput setaf 3)
99 magenta=$(tput setaf 5)
101 white=$bold$(tput setaf 7)
102 yellow=$(tput setaf 3)
108 dim_orange=$dim$orange
109 dim_magenta=$dim$magenta
112 dim_yellow=$dim$yellow
132 dim_orange="\e[1;33m"
133 dim_magenta="\e[1;35m"
136 dim_yellow="\e[1;33m"
142 if [[ "$USER" == "root" ]]; then
143 userStyle="\[$bold$red\]"
145 userStyle="\[$orange\]"
149 if [[ "$SSH_TTY" ]]; then
150 hostStyle="\[$bold$red\]"
152 hostStyle="\[$yellow\]"
155 # set the terminal title to the current working directory
156 PS1="\[\033]0;\w\007\]"
159 PS1+="\[$userStyle\]\u" # username
160 PS1+="\[$reset$white\]@"
161 PS1+="\[$hostStyle\]\h" # host
162 PS1+="\[$reset$white\]: "
163 PS1+="\[$green\]\w" # working directory
164 PS1+="\$(prompt_git \"$white on $cyan\")" # git repository details
166 PS1+="\[$reset$white\]\$ \[$reset\]" # $ (and reset color)