| @@ -17,8 +17,8 @@ declare -A symbols=( | |||
| [stash]="🐿" | |||
| [ahead]="+" | |||
| [behind]="-" | |||
| [smilie]="☺" | |||
| [frownie]="☹" | |||
| [smilie]="^_^" | |||
| [frownie]="O_o" | |||
| ) | |||
| last_section_bg= | |||
| @@ -26,13 +26,14 @@ last_section_bg= | |||
| # $1 - Text (FG) color of new section | |||
| # $2 - BG of new section | |||
| function section_separator() { | |||
| if [ $2 = $last_section_bg ]; then | |||
| PS1="${PS1}$(_CC ${1} ${2})${symbols[soft_separator]}" | |||
| if [ "$2" = "$last_section_bg" ]; then | |||
| PS1+="$(_CC ${BLACK} ${2})${symbols[soft_separator]}" | |||
| else | |||
| if [ "$2" ]; then | |||
| PS1="${PS1}$(_CC ${last_section_bg} ${2})${symbols[hard_separator]}" | |||
| PS1+="$(_CC $(_CBG2FG ${last_section_bg}) ${2})${symbols[hard_separator]}" | |||
| else | |||
| PS1="${PS1}${NORMAL}$(_CFG ${last_section_bg})${symbols[hard_separator]}${NORMAL}" | |||
| #echo "${last_section_bg} GAH!" | |||
| PS1+="${NORMAL}$(_CFG $(_CBG2FG ${last_section_bg}) )${symbols[hard_separator]}${NORMAL}" | |||
| fi | |||
| fi | |||
| } | |||
| @@ -41,12 +42,11 @@ function section_separator() { | |||
| # $2 - Text (FG) color | |||
| # $3 - BG Color | |||
| function section(){ | |||
| if [ $last_section_bg ]; then | |||
| $(section_separator $2 $3) | |||
| if [ "$last_section_bg" ]; then | |||
| section_separator ${2} ${3} | |||
| fi | |||
| last_section_bg=$3 | |||
| PS1="${PS1}$(_CC ${2} ${3})${1}" | |||
| echo "$(_CC ${2} ${3})${1}" | |||
| PS1+="$(_CC ${2} ${3} ${4})${1}" | |||
| } | |||
| @@ -54,50 +54,96 @@ function section(){ | |||
| # $1 - Default text (foreground) color | |||
| # $2 - Background color | |||
| function section_git_status() { | |||
| local default untracked stash clean ahead behind staged dirty diverged | |||
| default=$(_CC $1 $2) | |||
| untracked=$(_CC $GREEN $2) | |||
| stash=$(_CC $GREEN $2) | |||
| clean=$(_CC $GREEN $2) | |||
| ahead=$(_CC $YELLOW $2) | |||
| behind=$(_CC $YELLOW $2) | |||
| staged=$(_CC $CYAN $2) | |||
| dirty=$(_CC $RED $2) | |||
| diverged=$(_CC $RED $2) | |||
| branch=$(git rev-parse --abbrev-ref HEAD 2>/dev/null) | |||
| if [[ -n "$branch" ]]; then | |||
| $(section_separator $1 $2) | |||
| last_section_bg=$2 | |||
| PS1="${PS1}${default}${symbols[git]} $branch " | |||
| git_status=$(git status 2> /dev/null) | |||
| # If nothing changes the color, we can spot unhandled cases. | |||
| if [[ $git_status =~ 'Untracked files' ]]; then | |||
| PS1="${PS1}${untracked}${symbols[untracked]}" | |||
| fi | |||
| if git stash show &>/dev/null; then | |||
| PS1="${PS1}${stash}${symbols[stash]}" | |||
| fi | |||
| if [[ $git_status =~ 'Your branch is ahead' ]]; then | |||
| PS1="${PS1}${ahead}${symbols[ahead]}" | |||
| fi | |||
| if [[ $git_status =~ 'Your branch is behind' ]]; then | |||
| PS1="${PS1}${behind}${symbols[behind]}" | |||
| fi | |||
| if [[ $git_status =~ 'Changes to be committed' ]]; then | |||
| PS1="${PS1}${staged}${symbols[tick]}" | |||
| fi | |||
| if [[ $git_status =~ 'Changed but not updated' || | |||
| $git_status =~ 'Changes not staged' || | |||
| $git_status =~ 'Unmerged paths' ]]; then | |||
| PS1="${PS1}${dirty}${symbols[cross]}" | |||
| fi | |||
| if [[ $git_status =~ 'Your branch'.+diverged ]]; then | |||
| PS1="${PS1}${diverged}${symbols[enter]}" | |||
| fi | |||
| fi | |||
| local default untracked stash clean ahead behind staged dirty diverged | |||
| default=$(_CC $1 $2) | |||
| untracked=$(_CC $GREEN $2) | |||
| stash=$(_CC $GREEN $2) | |||
| clean=$(_CC $GREEN $2) | |||
| ahead=$(_CC $YELLOW $2) | |||
| behind=$(_CC $YELLOW $2) | |||
| staged=$(_CC $CYAN $2) | |||
| dirty=$(_CC $RED $2) | |||
| diverged=$(_CC $RED $2) | |||
| branch=$(git rev-parse --abbrev-ref HEAD 2>/dev/null) | |||
| if [[ -n "$branch" ]]; then | |||
| if [ "$last_section_bg" ]; then | |||
| section_separator $1 $2 | |||
| fi | |||
| last_section_bg=$2 | |||
| PS1+="${default} ${symbols[git]} $branch " | |||
| git_status=$(git status 2> /dev/null) | |||
| # If nothing changes the color, we can spot unhandled cases. | |||
| if [[ $git_status =~ 'Untracked files' ]]; then | |||
| PS1+="${symbols[untracked]}" | |||
| fi | |||
| if git stash show &>/dev/null; then | |||
| PS1+="${symbols[stash]}" | |||
| fi | |||
| if [[ $git_status =~ 'Your branch is ahead' ]]; then | |||
| PS1+="${symbols[ahead]}" | |||
| fi | |||
| if [[ $git_status =~ 'Your branch is behind' ]]; then | |||
| PS1+="${symbols[behind]}" | |||
| fi | |||
| if [[ $git_status =~ 'Changes to be committed' ]]; then | |||
| PS1+="${symbols[tick]}" | |||
| fi | |||
| if [[ $git_status =~ 'Changed but not updated' || | |||
| $git_status =~ 'Changes not staged' || | |||
| $git_status =~ 'Unmerged paths' ]]; then | |||
| PS1+="${symbols[cross]}" | |||
| fi | |||
| if [[ $git_status =~ 'Your branch'.+diverged ]]; then | |||
| PS1+="${symbols[enter]}" | |||
| fi | |||
| PS1+=" " | |||
| fi | |||
| } | |||
| # $1 - FG local | |||
| # $2 - BG User | |||
| # $3 - FG Remote | |||
| # $4 - BG Root | |||
| section_tty () { | |||
| local TTY=`ps aux | grep $$ | grep bash | awk '{ print $7 }'` | |||
| local SESS_SRC=`who | grep $TTY | awk '{ print $6 }'` | |||
| local USR=0 # 0 = User | 1 = Root | |||
| local FG=$1 | |||
| local BG=$2 | |||
| # Okay...Now who we be? | |||
| if [ `/usr/bin/whoami` = "root" ] ; then | |||
| USR=1 | |||
| BG=$4 | |||
| fi | |||
| SSH_IP=`echo $SSH_CLIENT | awk '{ print $1 }'` | |||
| if [ $SSH_IP ] ; then | |||
| FG=$3 | |||
| else | |||
| SSH_IP=`echo $SSH2_CLIENT | awk '{ print $1 }'` | |||
| if [ $SSH_IP ]; then | |||
| FG=$3 | |||
| fi | |||
| fi | |||
| if [ "$last_section_bg" ]; then | |||
| section_separator $1 $2 | |||
| fi | |||
| last_section_bg=$2 | |||
| PS1+="$(_CC $FG $BG) ${TTY} " | |||
| } | |||
| short_PWD () | |||
| { | |||
| local PRE= NAME="$1" LENGTH="$2"; | |||
| [[ "$NAME" != "${NAME#$HOME/}" || -z "${NAME#$HOME}" ]] && | |||
| PRE+='~' NAME="${NAME#$HOME}" LENGTH=$[LENGTH-1]; | |||
| ((${#NAME}>$LENGTH)) && NAME="/...${NAME:$[${#NAME}-LENGTH+4]}"; | |||
| echo "$PRE$NAME" | |||
| } | |||
| @@ -105,18 +151,20 @@ set_prompt() { | |||
| local lec="$?" | |||
| local color=$GREEN | |||
| local bg=$BG_LBLUE | |||
| local smilie=${symbols[smilie]} | |||
| local smilie=" ${symbols[smilie]} " | |||
| if [ $COLOR_PROMPT = yes ]; then | |||
| if [ $lec -ne 0 ]; then | |||
| color=$RED | |||
| smilie=${symbols[frownie]} | |||
| smilie=" ${symbols[frownie]} " | |||
| fi | |||
| PS1="${debian_chroot:+($debian_chroot)}Hi" #$(_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} " | |||
| #$(section $smilie $color $bg) | |||
| $(section "\\\\u" $GREEN $BG_GREY) | |||
| #$(section "\\\\w" $BLUE $BG_GREY) | |||
| #$(section_git_status $YELLOW $BG_LBLUE) | |||
| #$(section_separator) | |||
| 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} " | |||
| section $smilie $color $BG_BLACK 1 | |||
| section_tty $BLACK $BG_LBLUE $RED $BG_YELLOW | |||
| section " \u@\h " $BLUE $BG_LCYAN | |||
| section " $(short_PWD $PWD 20) " $LCYAN $BG_BLUE | |||
| section_git_status $YELLOW $BG_LBLUE | |||
| section_separator | |||
| unset last_section_bg | |||
| else | |||
| PS1="${debian_chroot:+($debian_chroot)}\u@\h:\w\$ " | |||
| fi | |||