From 08f42056fd0e62ee53ab14b4fe95a2b5e04eed16 Mon Sep 17 00:00:00 2001 From: killphi Date: Thu, 19 Dec 2013 14:10:35 +0100 Subject: format consistently - added sts=8 to modeline - vim commands: :retab :%s/\s+$// gg=G --- git-prompt.sh | 659 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 331 insertions(+), 328 deletions(-) diff --git a/git-prompt.sh b/git-prompt.sh index dea2967..2778d1f 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -1,174 +1,174 @@ - # don't set prompt if this is not interactive shell - [[ $- != *i* ]] && return +# don't set prompt if this is not interactive shell +[[ $- != *i* ]] && return - # bash version check - if [[ -z ${BASH_VERSION} || "${BASH_VERSINFO[0]}" -lt 4 ]]; then - echo "git-prompt requires bash-v4 or newer, git-prompt is not enabled." - return - fi +# bash version check +if [[ -z ${BASH_VERSION} || "${BASH_VERSINFO[0]}" -lt 4 ]]; then + echo "git-prompt requires bash-v4 or newer, git-prompt is not enabled." + return +fi - # clear vars from previous invocation - unset dir_color rc_color user_id_color root_id_color init_vcs_color clean_vcs_color - unset modified_vcs_color added_vcs_color addmoded_vcs_color untracked_vcs_color op_vcs_color detached_vcs_color hex_vcs_color - unset rawhex_len +# clear vars from previous invocation +unset dir_color rc_color user_id_color root_id_color init_vcs_color clean_vcs_color +unset modified_vcs_color added_vcs_color addmoded_vcs_color untracked_vcs_color op_vcs_color detached_vcs_color hex_vcs_color +unset rawhex_len - # work around for conflict with vte.sh - unset VTE_VERSION +# work around for conflict with vte.sh +unset VTE_VERSION ################################################################### CONFIG - ##### read config file if any. +##### read config file if any. - conf=git-prompt.conf; [[ -r $conf ]] && . $conf - conf=/etc/git-prompt.conf; [[ -r $conf ]] && . $conf - conf=~/.git-prompt.conf; [[ -r $conf ]] && . $conf - conf=~/.config/git-prompt.conf; [[ -r $conf ]] && . $conf - unset conf +conf=git-prompt.conf; [[ -r $conf ]] && . $conf +conf=/etc/git-prompt.conf; [[ -r $conf ]] && . $conf +conf=~/.git-prompt.conf; [[ -r $conf ]] && . $conf +conf=~/.config/git-prompt.conf; [[ -r $conf ]] && . $conf +unset conf - ##### set defaults if not set +##### set defaults if not set - git_module=${git_module:-on} - svn_module=${svn_module:-off} - hg_module=${hg_module:-on} - vim_module=${vim_module:-on} - virtualenv_module=${virtualenv_module:-on} - error_bell=${error_bell:-off} - cwd_cmd=${cwd_cmd:-\\w} +git_module=${git_module:-on} +svn_module=${svn_module:-off} +hg_module=${hg_module:-on} +vim_module=${vim_module:-on} +virtualenv_module=${virtualenv_module:-on} +error_bell=${error_bell:-off} +cwd_cmd=${cwd_cmd:-\\w} - #### dir, rc, root color - cols=`tput colors` # in emacs shell-mode tput colors returns -1 - if [[ -n "$cols" && $cols -ge 8 ]]; then # if terminal supports colors - dir_color=${dir_color:-CYAN} - rc_color=${rc_color:-red} - virtualenv_color=${virtualenv_color:-green} - user_id_color=${user_id_color:-blue} - root_id_color=${root_id_color:-magenta} - else # only B/W - dir_color=${dir_color:-bw_bold} - rc_color=${rc_color:-bw_bold} - fi - unset cols +#### dir, rc, root color +cols=`tput colors` # in emacs shell-mode tput colors returns -1 +if [[ -n "$cols" && $cols -ge 8 ]]; then # if terminal supports colors + dir_color=${dir_color:-CYAN} + rc_color=${rc_color:-red} + virtualenv_color=${virtualenv_color:-green} + user_id_color=${user_id_color:-blue} + root_id_color=${root_id_color:-magenta} +else # only B/W + dir_color=${dir_color:-bw_bold} + rc_color=${rc_color:-bw_bold} +fi +unset cols - #### prompt character, for root/non-root - prompt_char=${prompt_char:-'>'} - root_prompt_char=${root_prompt_char:-'>'} +#### prompt character, for root/non-root +prompt_char=${prompt_char:-'>'} +root_prompt_char=${root_prompt_char:-'>'} - #### vcs colors - init_vcs_color=${init_vcs_color:-WHITE} # initial - clean_vcs_color=${clean_vcs_color:-blue} # nothing to commit (working directory clean) - modified_vcs_color=${modified_vcs_color:-red} # Changed but not updated: - added_vcs_color=${added_vcs_color:-green} # Changes to be committed: - addmoded_vcs_color=${addmoded_vcs_color:-yellow} - untracked_vcs_color=${untracked_vcs_color:-BLUE} # Untracked files: - op_vcs_color=${op_vcs_color:-MAGENTA} - detached_vcs_color=${detached_vcs_color:-RED} +#### vcs colors +init_vcs_color=${init_vcs_color:-WHITE} # initial +clean_vcs_color=${clean_vcs_color:-blue} # nothing to commit (working directory clean) +modified_vcs_color=${modified_vcs_color:-red} # Changed but not updated: +added_vcs_color=${added_vcs_color:-green} # Changes to be committed: +addmoded_vcs_color=${addmoded_vcs_color:-yellow} +untracked_vcs_color=${untracked_vcs_color:-BLUE} # Untracked files: +op_vcs_color=${op_vcs_color:-MAGENTA} +detached_vcs_color=${detached_vcs_color:-RED} - hex_vcs_color=${hex_vcs_color:-BLACK} # gray +hex_vcs_color=${hex_vcs_color:-BLACK} # gray - max_file_list_length=${max_file_list_length:-100} - short_hostname=${short_hostname:-off} - upcase_hostname=${upcase_hostname:-on} - count_only=${count_only:-off} - rawhex_len=${rawhex_len:-5} +max_file_list_length=${max_file_list_length:-100} +short_hostname=${short_hostname:-off} +upcase_hostname=${upcase_hostname:-on} +count_only=${count_only:-off} +rawhex_len=${rawhex_len:-5} - aj_max=20 +aj_max=20 ##################################################################### post config - ################# make PARSE_VCS_STATUS - unset PARSE_VCS_STATUS - [[ $git_module = "on" ]] && type git >&/dev/null && PARSE_VCS_STATUS+="parse_git_status" - [[ $svn_module = "on" ]] && type svn >&/dev/null && PARSE_VCS_STATUS+="${PARSE_VCS_STATUS+||}parse_svn_status" - [[ $hg_module = "on" ]] && type hg >&/dev/null && PARSE_VCS_STATUS+="${PARSE_VCS_STATUS+||}parse_hg_status" - PARSE_VCS_STATUS+="${PARSE_VCS_STATUS+||}return" - ################# terminfo colors-16 - # - # black? 0 8 - # red 1 9 - # green 2 10 - # yellow 3 11 - # blue 4 12 - # magenta 5 13 - # cyan 6 14 - # white 7 15 - # - # terminfo setaf/setab - sets ansi foreground/background - # terminfo sgr0 - resets all attributes - # terminfo colors - number of colors - # - ################# Colors-256 - # To use foreground and background colors: - # Set the foreground color to index N: \033[38;5;${N}m - # Set the background color to index M: \033[48;5;${M}m - # To make vim aware of a present 256 color extension, you can either set - # the $TERM environment variable to xterm-256color or use vim's -T option - # to set the terminal. I'm using an alias in my bashrc to do this. At the - # moment I only know of two color schemes which is made for multi-color - # terminals like urxvt (88 colors) or xterm: inkpot and desert256, - - ### if term support colors, then use color prompt, else bold - - black='\['`tput sgr0; tput setaf 0`'\]' - red='\['`tput sgr0; tput setaf 1`'\]' - green='\['`tput sgr0; tput setaf 2`'\]' - yellow='\['`tput sgr0; tput setaf 3`'\]' - blue='\['`tput sgr0; tput setaf 4`'\]' - magenta='\['`tput sgr0; tput setaf 5`'\]' - cyan='\['`tput sgr0; tput setaf 6`'\]' - white='\['`tput sgr0; tput setaf 7`'\]' - - BLACK='\['`tput setaf 0; tput bold`'\]' - RED='\['`tput setaf 1; tput bold`'\]' - GREEN='\['`tput setaf 2; tput bold`'\]' - YELLOW='\['`tput setaf 3; tput bold`'\]' - BLUE='\['`tput setaf 4; tput bold`'\]' - MAGENTA='\['`tput setaf 5; tput bold`'\]' - CYAN='\['`tput setaf 6; tput bold`'\]' - WHITE='\['`tput setaf 7; tput bold`'\]' - - dim='\['`tput sgr0; tput setaf p1`'\]' # half-bright - - bw_bold='\['`tput bold`'\]' - - on='' - off=': ' - bell="\[`eval ${!error_bell} tput bel`\]" - colors_reset='\['`tput sgr0`'\]' - - # replace symbolic colors names to raw treminfo strings - init_vcs_color=${!init_vcs_color} - modified_vcs_color=${!modified_vcs_color} - untracked_vcs_color=${!untracked_vcs_color} - clean_vcs_color=${!clean_vcs_color} - added_vcs_color=${!added_vcs_color} - op_vcs_color=${!op_vcs_color} - addmoded_vcs_color=${!addmoded_vcs_color} - detached_vcs_color=${!detached_vcs_color} - hex_vcs_color=${!hex_vcs_color} - +################# make PARSE_VCS_STATUS +unset PARSE_VCS_STATUS +[[ $git_module = "on" ]] && type git >&/dev/null && PARSE_VCS_STATUS+="parse_git_status" +[[ $svn_module = "on" ]] && type svn >&/dev/null && PARSE_VCS_STATUS+="${PARSE_VCS_STATUS+||}parse_svn_status" +[[ $hg_module = "on" ]] && type hg >&/dev/null && PARSE_VCS_STATUS+="${PARSE_VCS_STATUS+||}parse_hg_status" +PARSE_VCS_STATUS+="${PARSE_VCS_STATUS+||}return" +################# terminfo colors-16 +# +# black? 0 8 +# red 1 9 +# green 2 10 +# yellow 3 11 +# blue 4 12 +# magenta 5 13 +# cyan 6 14 +# white 7 15 +# +# terminfo setaf/setab - sets ansi foreground/background +# terminfo sgr0 - resets all attributes +# terminfo colors - number of colors +# +################# Colors-256 +# To use foreground and background colors: +# Set the foreground color to index N: \033[38;5;${N}m +# Set the background color to index M: \033[48;5;${M}m +# To make vim aware of a present 256 color extension, you can either set +# the $TERM environment variable to xterm-256color or use vim's -T option +# to set the terminal. I'm using an alias in my bashrc to do this. At the +# moment I only know of two color schemes which is made for multi-color +# terminals like urxvt (88 colors) or xterm: inkpot and desert256, + +### if term support colors, then use color prompt, else bold + +black='\['`tput sgr0; tput setaf 0`'\]' +red='\['`tput sgr0; tput setaf 1`'\]' +green='\['`tput sgr0; tput setaf 2`'\]' +yellow='\['`tput sgr0; tput setaf 3`'\]' +blue='\['`tput sgr0; tput setaf 4`'\]' +magenta='\['`tput sgr0; tput setaf 5`'\]' +cyan='\['`tput sgr0; tput setaf 6`'\]' +white='\['`tput sgr0; tput setaf 7`'\]' + +BLACK='\['`tput setaf 0; tput bold`'\]' +RED='\['`tput setaf 1; tput bold`'\]' +GREEN='\['`tput setaf 2; tput bold`'\]' +YELLOW='\['`tput setaf 3; tput bold`'\]' +BLUE='\['`tput setaf 4; tput bold`'\]' +MAGENTA='\['`tput setaf 5; tput bold`'\]' +CYAN='\['`tput setaf 6; tput bold`'\]' +WHITE='\['`tput setaf 7; tput bold`'\]' + +dim='\['`tput sgr0; tput setaf p1`'\]' # half-bright + +bw_bold='\['`tput bold`'\]' + +on='' +off=': ' +bell="\[`eval ${!error_bell} tput bel`\]" +colors_reset='\['`tput sgr0`'\]' + +# replace symbolic colors names to raw treminfo strings +init_vcs_color=${!init_vcs_color} +modified_vcs_color=${!modified_vcs_color} +untracked_vcs_color=${!untracked_vcs_color} +clean_vcs_color=${!clean_vcs_color} +added_vcs_color=${!added_vcs_color} +op_vcs_color=${!op_vcs_color} +addmoded_vcs_color=${!addmoded_vcs_color} +detached_vcs_color=${!detached_vcs_color} +hex_vcs_color=${!hex_vcs_color} + +unset PROMPT_COMMAND + +####### work around for MC bug. +####### specifically exclude emacs, want full when running inside emacs +if [[ -z "$TERM" || ("$TERM" = "dumb" && -z "$INSIDE_EMACS") || -n "$MC_SID" ]]; then unset PROMPT_COMMAND + PS1="\w$prompt_char " + return 0 +fi - ####### work around for MC bug. - ####### specifically exclude emacs, want full when running inside emacs - if [[ -z "$TERM" || ("$TERM" = "dumb" && -z "$INSIDE_EMACS") || -n "$MC_SID" ]]; then - unset PROMPT_COMMAND - PS1="\w$prompt_char " - return 0 - fi - - #################################################################### MARKERS - if [[ "$LC_CTYPE $LC_ALL" =~ "UTF" && $TERM != "linux" ]]; then - elipses_marker="…" - else - elipses_marker="..." - fi +#################################################################### MARKERS +if [[ "$LC_CTYPE $LC_ALL" =~ "UTF" && $TERM != "linux" ]]; then + elipses_marker="…" +else + elipses_marker="..." +fi - export who_where +export who_where cwd_truncate() { @@ -195,7 +195,7 @@ cwd_truncate() { # split path into: head='~/', truncateble middle, last_dir local cwd_max_length=$1 - + if [[ "$cwd" =~ '(~?/)(.*/)([^/]*)$' ]] ; then # only valid if path have more than 1 dir local path_head=${BASH_REMATCH[1]} local path_middle=${BASH_REMATCH[2]} @@ -205,24 +205,24 @@ cwd_truncate() { [[ $cwd_middle_max < 0 ]] && cwd_middle_max=0 - # trunc middle if over limit + # trunc middle if over limit if [[ ${#path_middle} -gt $(( $cwd_middle_max + ${#elipses_marker} + 5 )) ]]; then - # truncate - middle_tail=${path_middle:${#path_middle}-${cwd_middle_max}} + # truncate + middle_tail=${path_middle:${#path_middle}-${cwd_middle_max}} - # trunc on dir boundary (trunc 1st, probably tuncated dir) - [[ $middle_tail =~ '[^/]*/(.*)$' ]] - middle_tail=${BASH_REMATCH[1]} + # trunc on dir boundary (trunc 1st, probably tuncated dir) + [[ $middle_tail =~ '[^/]*/(.*)$' ]] + middle_tail=${BASH_REMATCH[1]} - # use truncated only if we cut at least 4 chars - if [[ $(( ${#path_middle} - ${#middle_tail})) -gt 4 ]]; then - cwd=$path_head$elipses_marker$middle_tail$path_last_dir - fi + # use truncated only if we cut at least 4 chars + if [[ $(( ${#path_middle} - ${#middle_tail})) -gt 4 ]]; then + cwd=$path_head$elipses_marker$middle_tail$path_last_dir + fi fi fi return - } +} set_shell_label() { @@ -258,98 +258,101 @@ set_shell_label() { ;; esac fi - } +} - export -f set_shell_label +export -f set_shell_label ###################################################### ID (user name) - id=`id -un` - id=${id#$default_user} +id=`id -un` +id=${id#$default_user} ########################################################### TTY - tty=`tty` - tty=`echo $tty | sed "s:/dev/pts/:p:; s:/dev/tty::" ` # RH tty devs - tty=`echo $tty | sed "s:/dev/vc/:vc:" ` # gentoo tty devs - - if [[ "$TERM" = "screen" ]] ; then - - # [ "$WINDOW" = "" ] && WINDOW="?" - # - # # if under screen then make tty name look like s1-p2 - # # tty="${WINDOW:+s}$WINDOW${WINDOW:+-}$tty" - # tty="${WINDOW:+s}$WINDOW" # replace tty name with screen number - tty="$WINDOW" # replace tty name with screen number - fi +tty=`tty` +tty=`echo $tty | sed "s:/dev/pts/:p:; s:/dev/tty::" ` # RH tty devs +tty=`echo $tty | sed "s:/dev/vc/:vc:" ` # gentoo tty devs - # we don't need tty name under X11 - case $TERM in - xterm* | rxvt* | gnome-terminal | konsole | eterm* | wterm | cygwin) unset tty ;; - *);; - esac +if [[ "$TERM" = "screen" ]] ; then - dir_color=${!dir_color} - rc_color=${!rc_color} - virtualenv_color=${!virtualenv_color} - user_id_color=${!user_id_color} - root_id_color=${!root_id_color} - - ########################################################### HOST - ### we don't display home host/domain $SSH_* set by SSHD or keychain - - # How to find out if session is local or remote? Working with "su -", ssh-agent, and so on ? - - ## is sshd our parent? - # if { for ((pid=$$; $pid != 1 ; pid=`ps h -o pid --ppid $pid`)); do ps h -o command -p $pid; done | grep -q sshd && echo == REMOTE ==; } - #then - - host=${HOSTNAME} - if [[ $short_hostname = "on" ]]; then - if [[ "$(uname)" =~ "CYGWIN" ]]; then - host=`hostname` - else - host=`hostname -s` - fi - fi - host=${host#$default_host} - uphost=`echo ${host} | tr a-z-. A-Z_` - if [[ $upcase_hostname = "on" ]]; then - host=${uphost} - fi - - host_color=${uphost}_host_color - host_color=${!host_color} - if [[ -z $host_color && -x /usr/bin/cksum ]] ; then - cksum_color_no=`echo $uphost | cksum | awk '{print $1%6}'` - color_index=(green yellow blue magenta cyan white) # FIXME: bw, color-256 - host_color=${color_index[cksum_color_no]} + # [ "$WINDOW" = "" ] && WINDOW="?" + # + # # if under screen then make tty name look like s1-p2 + # # tty="${WINDOW:+s}$WINDOW${WINDOW:+-}$tty" + # tty="${WINDOW:+s}$WINDOW" # replace tty name with screen number + tty="$WINDOW" # replace tty name with screen number +fi + +# we don't need tty name under X11 +case $TERM in + xterm* | rxvt* | gnome-terminal | konsole | eterm* | wterm | cygwin) + unset tty + ;; + *) + ;; +esac + +dir_color=${!dir_color} +rc_color=${!rc_color} +virtualenv_color=${!virtualenv_color} +user_id_color=${!user_id_color} +root_id_color=${!root_id_color} + +########################################################### HOST +### we don't display home host/domain $SSH_* set by SSHD or keychain + +# How to find out if session is local or remote? Working with "su -", ssh-agent, and so on ? + +## is sshd our parent? +# if { for ((pid=$$; $pid != 1 ; pid=`ps h -o pid --ppid $pid`)); do ps h -o command -p $pid; done | grep -q sshd && echo == REMOTE ==; } +#then + +host=${HOSTNAME} +if [[ $short_hostname = "on" ]]; then + if [[ "$(uname)" =~ "CYGWIN" ]]; then + host=`hostname` + else + host=`hostname -s` fi - - host_color=${!host_color} - - # we might already have short host name - host=${host%.$default_domain} +fi +host=${host#$default_host} +uphost=`echo ${host} | tr a-z-. A-Z_` +if [[ $upcase_hostname = "on" ]]; then + host=${uphost} +fi + +host_color=${uphost}_host_color +host_color=${!host_color} +if [[ -z $host_color && -x /usr/bin/cksum ]] ; then + cksum_color_no=`echo $uphost | cksum | awk '{print $1%6}'` + color_index=(green yellow blue magenta cyan white) # FIXME: bw, color-256 + host_color=${color_index[cksum_color_no]} +fi + +host_color=${!host_color} + +# we might already have short host name +host=${host%.$default_domain} #################################################################### WHO_WHERE - # [[user@]host[-tty]] +# [[user@]host[-tty]] - if [[ -n $id || -n $host ]] ; then - [[ -n $id && -n $host ]] && at='@' || at='' - color_who_where="${id}${host:+$host_color$at$host}${tty:+ $tty}" - plain_who_where="${id}$at$host" +if [[ -n $id || -n $host ]] ; then + [[ -n $id && -n $host ]] && at='@' || at='' + color_who_where="${id}${host:+$host_color$at$host}${tty:+ $tty}" + plain_who_where="${id}$at$host" - # add trailing " " - color_who_where="$color_who_where " - plain_who_where="$plain_who_where " + # add trailing " " + color_who_where="$color_who_where " + plain_who_where="$plain_who_where " - # if root then make it root_color - if [ "$id" == "root" ] ; then - user_id_color=$root_id_color - prompt_char="$root_prompt_char" - fi - color_who_where="$user_id_color$color_who_where$colors_reset" - else - color_who_where='' + # if root then make it root_color + if [ "$id" == "root" ] ; then + user_id_color=$root_id_color + prompt_char="$root_prompt_char" fi + color_who_where="$user_id_color$color_who_where$colors_reset" +else + color_who_where='' +fi parse_svn_status() { @@ -360,27 +363,27 @@ parse_svn_status() { ### get rev eval ` - svn info | - sed -n " - s@^URL[^/]*//@repo_dir=@p - s/^Revision: /rev=/p - " + svn info | + sed -n " + s@^URL[^/]*//@repo_dir=@p + s/^Revision: /rev=/p + " ` ### get status unset status modified added clean init added mixed untracked op detached eval `svn status 2>/dev/null | - sed -n ' - s/^A... \([^.].*\)/modified=modified; modified_files[${#modified_files[@]}]=\"\1\";/p - s/^M... \([^.].*\)/modified=modified; modified_files[${#modified_files[@]}]=\"\1\";/p - s/^\?... \([^.].*\)/untracked=untracked; untracked_files[${#untracked_files[@]}]=\"\1\";/p - ' + sed -n ' + s/^A... \([^.].*\)/modified=modified; modified_files[${#modified_files[@]}]=\"\1\";/p + s/^M... \([^.].*\)/modified=modified; modified_files[${#modified_files[@]}]=\"\1\";/p + s/^\?... \([^.].*\)/untracked=untracked; untracked_files[${#untracked_files[@]}]=\"\1\";/p + ' ` # TODO branch detection if standard repo layout [[ -z $modified ]] && [[ -z $untracked ]] && clean=clean vcs_info=svn:r$rev - } +} parse_hg_status() { @@ -393,12 +396,12 @@ parse_hg_status() { unset status modified added clean init added mixed untracked op detached eval `hg status 2>/dev/null | - sed -n ' - s/^M \([^.].*\)/modified=modified; modified_files[${#modified_files[@]}]=\"\1\";/p - s/^A \([^.].*\)/added=added; added_files[${#added_files[@]}]=\"\1\";/p - s/^R \([^.].*\)/added=added;/p - s/^! \([^.].*\)/modified=modified;/p - s/^? \([^.].*\)/untracked=untracked; untracked_files[${#untracked_files[@]}]=\\"\1\\";/p + sed -n ' + s/^M \([^.].*\)/modified=modified; modified_files[${#modified_files[@]}]=\"\1\";/p + s/^A \([^.].*\)/added=added; added_files[${#added_files[@]}]=\"\1\";/p + s/^R \([^.].*\)/added=added;/p + s/^! \([^.].*\)/modified=modified;/p + s/^? \([^.].*\)/untracked=untracked; untracked_files[${#untracked_files[@]}]=\\"\1\\";/p '` branch=`hg branch 2> /dev/null` @@ -410,7 +413,7 @@ parse_hg_status() { if [[ "$bookmark" ]] ; then vcs_info+=/$bookmark fi - } +} @@ -427,9 +430,9 @@ parse_git_status() { vcs=git ########################################################## GIT STATUS - added_files=() - modified_files=() - untracked_files=() + added_files=() + modified_files=() + untracked_files=() [[ $rawhex_len -gt 0 ]] && freshness="$dim=" unset branch status modified added clean init added mixed untracked op detached @@ -437,40 +440,40 @@ parse_git_status() { # work around for VTE bug (hang on printf) unset VTE_VERSION - # info not in porcelain status + # info not in porcelain status eval " $( - git status 2>/dev/null | - sed -n ' - s/^\(# \)*On branch /branch=/p - s/^nothing to commi.*/clean=clean/p - s/^\(# \)*Initial commi.*/init=init/p - s/^\(# \)*Your branch is ahead of \(.\).\+\1 by [[:digit:]]\+ commit.*/freshness=${WHITE}↑/p - s/^\(# \)*Your branch is behind \(.\).\+\1 by [[:digit:]]\+ commit.*/freshness=${YELLOW}↓/p - s/^\(# \)*Your branch and \(.\).\+\1 have diverged.*/freshness=${YELLOW}↕/p - ' + git status 2>/dev/null | + sed -n ' + s/^\(# \)*On branch /branch=/p + s/^nothing to commi.*/clean=clean/p + s/^\(# \)*Initial commi.*/init=init/p + s/^\(# \)*Your branch is ahead of \(.\).\+\1 by [[:digit:]]\+ commit.*/freshness=${WHITE}↑/p + s/^\(# \)*Your branch is behind \(.\).\+\1 by [[:digit:]]\+ commit.*/freshness=${YELLOW}↓/p + s/^\(# \)*Your branch and \(.\).\+\1 have diverged.*/freshness=${YELLOW}↕/p + ' )" - # porcelain file list - # TODO: sed-less -- http://tldp.org/LDP/abs/html/arrays.html -- Example 27-5 + # porcelain file list + # TODO: sed-less -- http://tldp.org/LDP/abs/html/arrays.html -- Example 27-5 - # git bug: (was reported to git@vger.kernel.org ) - # echo 1 > "with space" - # git status --porcelain - # ?? with space <------------ NO QOUTES - # git add with\ space - # git status --porcelain - # A "with space" <------------- WITH QOUTES + # git bug: (was reported to git@vger.kernel.org ) + # echo 1 > "with space" + # git status --porcelain + # ?? with space <------------ NO QOUTES + # git add with\ space + # git status --porcelain + # A "with space" <------------- WITH QOUTES eval " $( - git status --porcelain 2>/dev/null | - sed -n ' - s,^[MARC]. \([^\"][^/]*/\?\).*, added=added; [[ \" ${added_files[@]} \" =~ \" \1 \" ]] || added_files[${#added_files[@]}]=\"\1\",p - s,^[MARC]. \"\([^/]\+/\?\).*\"$, added=added; [[ \" ${added_files[@]} \" =~ \" \1 \" ]] || added_files[${#added_files[@]}]=\"\1\",p - s,^.[MAU] \([^\"][^/]*/\?\).*, modified=modified; [[ \" ${modified_files[@]} \" =~ \" \1 \" ]] || modified_files[${#modified_files[@]}]=\"\1\",p - s,^.[MAU] \"\([^/]\+/\?\).*\"$, modified=modified; [[ \" ${modified_files[@]} \" =~ \" \1 \" ]] || modified_files[${#modified_files[@]}]=\"\1\",p - s,^?? \([^\"][^/]*/\?\).*, untracked=untracked; [[ \" ${untracked_files[@]} \" =~ \" \1 \" ]] || untracked_files[${#untracked_files[@]}]=\"\1\",p - s,^?? \"\([^/]\+/\?\).*\"$, untracked=untracked; [[ \" ${untracked_files[@]} \" =~ \" \1 \" ]] || untracked_files[${#untracked_files[@]}]=\"\1\",p - ' # |tee /dev/tty + git status --porcelain 2>/dev/null | + sed -n ' + s,^[MARC]. \([^\"][^/]*/\?\).*, added=added; [[ \" ${added_files[@]} \" =~ \" \1 \" ]] || added_files[${#added_files[@]}]=\"\1\",p + s,^[MARC]. \"\([^/]\+/\?\).*\"$, added=added; [[ \" ${added_files[@]} \" =~ \" \1 \" ]] || added_files[${#added_files[@]}]=\"\1\",p + s,^.[MAU] \([^\"][^/]*/\?\).*, modified=modified; [[ \" ${modified_files[@]} \" =~ \" \1 \" ]] || modified_files[${#modified_files[@]}]=\"\1\",p + s,^.[MAU] \"\([^/]\+/\?\).*\"$, modified=modified; [[ \" ${modified_files[@]} \" =~ \" \1 \" ]] || modified_files[${#modified_files[@]}]=\"\1\",p + s,^?? \([^\"][^/]*/\?\).*, untracked=untracked; [[ \" ${untracked_files[@]} \" =~ \" \1 \" ]] || untracked_files[${#untracked_files[@]}]=\"\1\",p + s,^?? \"\([^/]\+/\?\).*\"$, untracked=untracked; [[ \" ${untracked_files[@]} \" =~ \" \1 \" ]] || untracked_files[${#untracked_files[@]}]=\"\1\",p + ' # |tee /dev/tty )" if ! grep -q "^ref:" "$git_dir/HEAD" 2>/dev/null; then @@ -503,7 +506,7 @@ parse_git_status() { op="rebase -m" # ??? branch="$(cat "$git_dir/.dotest-merge/head-name")" - # lvv: not always works. Should ./.dotest be used instead? + # lvv: not always works. Should ./.dotest be used instead? elif [[ -f "$git_dir/MERGE_HEAD" ]] ; then op="merge" # ??? branch="$(git symbolic-ref HEAD 2>/dev/null)" @@ -514,8 +517,8 @@ parse_git_status() { else [[ -f "$git_dir/BISECT_LOG" ]] && op="bisect" # ??? branch="$(git symbolic-ref HEAD 2>/dev/null)" || \ - # branch="$(git describe --exact-match HEAD 2>/dev/null)" || \ - # branch="$(cut -c1-7 "$git_dir/HEAD")..." + # branch="$(git describe --exact-match HEAD 2>/dev/null)" || \ + # branch="$(cut -c1-7 "$git_dir/HEAD")..." fi @@ -531,9 +534,9 @@ parse_git_status() { #### branch branch=${branch/#master/M} - # another method of above: - # branch=$(git symbolic-ref -q HEAD || { echo -n "detached:" ; git name-rev --name-only HEAD 2>/dev/null; } ) - # branch=${branch#refs/heads/} + # another method of above: + # branch=$(git symbolic-ref -q HEAD || { echo -n "detached:" ; git name-rev --name-only HEAD 2>/dev/null; } ) + # branch=${branch#refs/heads/} ### compose vcs_info @@ -548,14 +551,14 @@ parse_git_status() { elif [[ "$op" ]]; then branch="$op:$branch" if [[ "$op" == "merge" ]] ; then - branch+="<--$(git name-rev --name-only $(<$git_dir/MERGE_HEAD))" + branch+="<--$(git name-rev --name-only $(<$git_dir/MERGE_HEAD))" fi #branch="<$branch>" fi vcs_info="$branch$freshness$rawhex" fi - } +} parse_vcs_status() { @@ -579,10 +582,10 @@ parse_vcs_status() { status=${status:-$added} status=${status:-$untracked} status=${status:-$init} - # at least one should be set - : ${status?prompt internal error: git status} + # at least one should be set + : ${status?prompt internal error: git status} eval vcs_color="\${${status}_vcs_color}" - # no def: vcs_color=${vcs_color:-$WHITE} # default + # no def: vcs_color=${vcs_color:-$WHITE} # default ### VIM @@ -591,22 +594,22 @@ parse_vcs_status() { # equivalent to vim_glob=`ls .*.vim` but without running ls unset vim_glob vim_file vim_files old_nullglob=`shopt -p nullglob` - shopt -s nullglob - vim_glob=`echo .*.sw?` + shopt -s nullglob + vim_glob=`echo .*.sw?` eval $old_nullglob if [[ $vim_glob ]]; then - set $vim_glob - #vim_file=${vim_glob#.} - if [[ $# > 1 ]] ; then - vim_files="*" - else - vim_file=${1#.} - vim_file=${vim_file/.sw?/} - [[ .${vim_file}.swp -nt $vim_file ]] && vim_files=$vim_file - fi - # if swap is newer, then this is unsaved vim session - # [temoto custom] if swap is older, then it must be deleted, so show all swaps. + set $vim_glob + #vim_file=${vim_glob#.} + if [[ $# > 1 ]] ; then + vim_files="*" + else + vim_file=${1#.} + vim_file=${vim_file/.sw?/} + [[ .${vim_file}.swp -nt $vim_file ]] && vim_files=$vim_file + fi + # if swap is newer, then this is unsaved vim session + # [temoto custom] if swap is older, then it must be deleted, so show all swaps. fi fi @@ -638,30 +641,30 @@ parse_vcs_status() { head_local="${head_local+$vcs_color$head_local }" #above_local="${head_local+$vcs_color$head_local\n}" #tail_local="${tail_local+$vcs_color $tail_local}${dir_color}" - } +} parse_virtualenv_status() { - unset virtualenv + unset virtualenv - [[ $virtualenv_module = "on" ]] || return 1 + [[ $virtualenv_module = "on" ]] || return 1 - if [[ -n "$VIRTUAL_ENV" ]] ; then - virtualenv=`basename $VIRTUAL_ENV` - rc="$rc $virtualenv_color<$virtualenv> " - fi - } + if [[ -n "$VIRTUAL_ENV" ]] ; then + virtualenv=`basename $VIRTUAL_ENV` + rc="$rc $virtualenv_color<$virtualenv> " + fi +} disable_set_shell_label() { trap - DEBUG >& /dev/null - } +} # show currently executed command in label enable_set_shell_label() { disable_set_shell_label - # check for BASH_SOURCE being empty, no point running set_shell_label on every line of .bashrc + # check for BASH_SOURCE being empty, no point running set_shell_label on every line of .bashrc trap '[[ -z "$BASH_SOURCE" && ($BASH_COMMAND != prompt_command_function) ]] && - set_shell_label $BASH_COMMAND' DEBUG >& /dev/null - } + set_shell_label $BASH_COMMAND' DEBUG >& /dev/null +} declare -ft disable_set_shell_label declare -ft enable_set_shell_label @@ -683,7 +686,7 @@ j (){ fi done echo '?' - } +} alias jumpstart='echo ${aj_dir_list[@]}' @@ -701,12 +704,12 @@ prompt_command_function() { cwd=${PWD/$HOME/\~} # substitute "~" set_shell_label "${cwd##[/~]*/}/" # default label - path last dir - parse_virtualenv_status + parse_virtualenv_status parse_vcs_status # autojump if [[ ${aj_dir_list[aj_idx%aj_max]} != $PWD ]] ; then - aj_dir_list[++aj_idx%aj_max]="$PWD" + aj_dir_list[++aj_idx%aj_max]="$PWD" fi # if cwd_cmd have back-slash, then assign it value to cwd @@ -716,12 +719,12 @@ prompt_command_function() { PS1="$colors_reset$rc$head_local$color_who_where$dir_color$cwd$tail_local$dir_color$prompt_char $colors_reset" unset head_local tail_local pwd - } +} - PROMPT_COMMAND=prompt_command_function +PROMPT_COMMAND=prompt_command_function - enable_set_shell_label +enable_set_shell_label - unset rc id tty modified_files file_list +unset rc id tty modified_files file_list -# vim: set ft=sh ts=8 sw=8 et: +# vim: set ft=sh ts=8 sts=8 sw=8 et: -- cgit v1.2.3