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"
139 charStyle="$reset$bold$black"
140 gitStyle="\[$white\]on \[$magenta\]"
141 case "$BACKGROUND" in
143 hostStyle="$reset$cyan"
146 hostStyle="$reset$blue"
149 wdirStyle="$reset$green"
153 if [[ "$USER" == "root" ]]; then
154 userStyle="$bold$red"
160 # display the user, host and current working directory in the terminal title
162 *rxvt*|screen*|*term*|vt100)
163 PS1="\[\033]0;\u@\h:\w\007\]"
166 PS1+"\[\033k\u@\h:\w\033\\\]" # Set screen/tmux caption
177 PS1+="\[$userStyle\]\u" # username
178 PS1+="\[$charStyle\]@"
179 PS1+="\[$hostStyle\]\h " # host
180 #PS1+="\[$charStyle\]: "
181 PS1+="\[$wdirStyle\]\W " # working directory
182 PS1+="\$(prompt_git \"$gitStyle\")" # git repository details
184 PS1+="\[$charStyle\]\$ \[$reset\]" # $ (and reset color)