3 # bash_prompt; adapted from
4 # https://github.com/necolas/dotfiles/blob/master/shell/bash_prompt
7 # nicolas@host: ~/.dotfiles on master [+!?$]
10 # Screenshot: http://i.imgur.com/DSJ1G.png
11 # iTerm2 prefs: import Solarized theme (disable bright colors for bold text)
12 # Color ref: http://vim.wikia.com/wiki/Xterm256_color_names_for_console_Vim
13 # More tips: http://www.cyberciti.biz/tips/howto-linux-unix-bash-shell-setup-prompt.html
19 # check if the current directory is in a git repository
20 if [ $(git rev-parse --is-inside-work-tree &>/dev/null; printf "%s" $?) == 0 ]; then
22 # check if the current directory is in .git before running git checks
23 if [ "$(git rev-parse --is-inside-git-dir 2> /dev/null)" == "false" ]; then
25 # ensure index is up to date
26 #git update-index --really-refresh -q &>/dev/null
28 # check for uncommitted changes in the index
29 if ! $(git diff --quiet --ignore-submodules --cached); then
33 # check for unstaged changes
34 if ! $(git diff-files --quiet --ignore-submodules --); then
38 # check for untracked files
39 if [ -n "$(git ls-files --others --exclude-standard)" ]; then
43 # check for stashed files
44 if $(git rev-parse --verify refs/stash &>/dev/null); then
50 # get the short symbolic ref
51 # if HEAD isn't a symbolic ref, get the short SHA
52 # otherwise, just give up
53 branchName="$(git symbolic-ref --quiet --short HEAD 2> /dev/null || \
54 git rev-parse --short HEAD 2> /dev/null || \
57 [ -n "$s" ] && s=" [$s]"
59 printf "%s" "$1$branchName$s"
93 if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
94 tput sgr0 # reset colors
101 # (https://github.com/altercation/solarized/tree/master/iterm2-colors-solarized#the-values)
102 black=$(tput setaf 0)
103 blue=$(tput setaf 33)
104 cyan=$(tput setaf 37)
105 green=$(tput setaf 64)
106 orange=$(tput setaf 166)
107 purple=$(tput setaf 125)
108 red=$(tput setaf 124)
109 white=$(tput setaf 15)
110 yellow=$(tput setaf 136)
116 dim_orange=$dim$orange
117 dim_magenta=$dim$magenta
120 dim_yellow=$dim$yellow
140 dim_orange="\e[1;33m"
141 dim_magenta="\e[1;35m"
144 dim_yellow="\e[1;33m"
150 if [[ "$USER" == "root" ]]; then
151 userStyle="\[$bold$red\]"
153 userStyle="\[$orange\]"
157 if [[ "$SSH_TTY" ]]; then
158 hostStyle="\[$bold$red\]"
160 hostStyle="\[$yellow\]"
163 # set the terminal title to the current working directory
164 PS1="\[\033]0;\w\007\]"
167 PS1+="\[$userStyle\]\u" # username
168 PS1+="\[$reset$white\]@"
169 PS1+="\[$hostStyle\]\h" # host
170 PS1+="\[$reset$white\]: "
171 PS1+="\[$green\]\w" # working directory
172 PS1+="\$(prompt_git \"$white on $cyan\")" # git repository details
174 PS1+="\[$reset$white\]\$ \[$reset\]" # $ (and reset color)