# define symbols declare -A symbols=( [hard_separator]="▶" [soft_separator]="|" [git]="" [lock]="" [flag]="⚑" [plus]="✚" [tick]="✔" [cross]="✘" [enter]="⏎" [python]="λ" [battery_charging]="⚡" [battery_discharging]="▮" [untracked]="U" [stash]="🐿" [ahead]="+" [behind]="-" [smilie]="☺" [frownie]="☹" ) # This function was modified from one found @ https://www.reddit.com/r/linux/comments/2uf5uu/this_is_my_bash_prompt_which_is_your_favorite/?st=jikgswh4&sh=371ba8bf function _git_status() { local unknown untracked stash clean ahead behind staged dirty diverged unknown=$(_CC $BLUE $BG_DGREY) untracked=$(_CC $GREEN $BG_DGREY) stash=$(_CC $GREEN $BG_DGREY) clean=$(_CC $GREEN $BG_DGREY) ahead=$(_CC $YELLOW $BG_DGREY) behind=$(_CC $YELLOW $BG_DGREY) staged=$(_CC $CYAN $BG_DGREY) dirty=$(_CC $RED $BG_DGREY) diverged=$(_CC $RED $BG_DGREY) branch=$(git rev-parse --abbrev-ref HEAD 2>/dev/null) if [[ -n "$branch" ]]; then git_status=$(git status 2> /dev/null) # If nothing changes the color, we can spot unhandled cases. color=$unknown if [[ $git_status =~ 'Untracked files' ]]; then color=$untracked branch="${branch}?" fi if git stash show &>/dev/null; then color=$stash branch="${branch}+" fi if [[ $git_status =~ 'working directory clean' ]]; then color=$clean fi if [[ $git_status =~ 'Your branch is ahead' ]]; then color=$ahead branch="${branch}>" fi if [[ $git_status =~ 'Your branch is behind' ]]; then color=$behind branch="${branch}<" fi if [[ $git_status =~ 'Changes to be committed' ]]; then color=$staged fi if [[ $git_status =~ 'Changed but not updated' || $git_status =~ 'Changes not staged' || $git_status =~ 'Unmerged paths' ]]; then color=$dirty fi if [[ $git_status =~ 'Your branch'.+diverged ]]; then color=$diverged branch="${branch}!" fi echo -n "${color}${symbols[git]}${branch}" fi } set_prompt() { local lec="$?" if [ $COLOR_PROMPT = yes ]; then if [ $lec -ne 0 ]; then smilie="$(_CC $RED $BG_DGREY)${symbols[frownie]}" else smilie="$(_CC $GREEN $BG_DGREY)${symbols[smilie]}" fi PS1="${debian_chroot:+($debian_chroot)}$(_CC $GREEN $BG_DGREY)\u $(_CC $LBLUE $BG_DGREY)\w$(_CC $DEFAULT $BG_DGREY)|${smilie}$(_CC $DEFAULT $BG_DGREY)|$(_git_status)${NORMAL}$(_CFG $DGREY)${symbols[hard_separator]}${NORMAL} " else PS1="${debian_chroot:+($debian_chroot)}\u@\h:\w\$ " fi } PROMPT_COMMAND="set_prompt"