From fca62c16161c8b0bbcb215a4d0b6f21030113dcf Mon Sep 17 00:00:00 2001 From: Marc-Antoine Ruel Date: Tue, 27 Aug 2013 11:38:57 -0400 Subject: Fix support for non English UI. When git is localized, output is in the native language, so the regexp fails. Forces output to be in English. --- git-prompt.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/git-prompt.sh b/git-prompt.sh index f99a1d0..8ab9103 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -431,7 +431,7 @@ parse_git_status() { # info not in porcelain status eval " $( - git status 2>/dev/null | + LANG=C git status 2>/dev/null | sed -n ' s/^# On branch /branch=/p s/^nothing to commi.*/clean=clean/p @@ -454,7 +454,7 @@ parse_git_status() { # A "with space" <------------- WITH QOUTES eval " $( - git status --porcelain 2>/dev/null | + LANG=C 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 -- cgit v1.2.3 From eeff805e0bcdab5317ed1027bef2b625a8f7f94b Mon Sep 17 00:00:00 2001 From: Leonid Volnitsky Date: Tue, 10 Dec 2013 19:58:09 +0200 Subject: fix for issue #37 (branch detection with new git) --- git-prompt.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/git-prompt.sh b/git-prompt.sh index f99a1d0..1cf4b4e 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -433,12 +433,12 @@ parse_git_status() { eval " $( git status 2>/dev/null | sed -n ' - s/^# On branch /branch=/p + 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 + 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 ' )" -- cgit v1.2.3 From 6e32ba0ca078f94194d5ce23b5307f0a4fd293fd Mon Sep 17 00:00:00 2001 From: Leonid Volnitsky Date: Wed, 11 Dec 2013 23:49:16 +0200 Subject: work around for vte.sh --- git-prompt.sh | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/git-prompt.sh b/git-prompt.sh index 1cf4b4e..adb6945 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -1,13 +1,18 @@ # don't set prompt if this is not interactive shell [[ $- != *i* ]] && return + # 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 + ################################################################### CONFIG ##### read config file if any. - 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 conf=git-prompt.conf; [[ -r $conf ]] && . $conf conf=/etc/git-prompt.conf; [[ -r $conf ]] && . $conf @@ -429,6 +434,9 @@ parse_git_status() { unset branch status modified added clean init added mixed untracked op detached + # work around for VTE bug (hang on printf) + unset VTE_VERSION + # info not in porcelain status eval " $( git status 2>/dev/null | -- cgit v1.2.3 From fd0b88da255bfd499c76352e281106d4566149a7 Mon Sep 17 00:00:00 2001 From: Leonid Volnitsky Date: Sun, 15 Dec 2013 11:19:57 +0200 Subject: bash-v4 or newer mandated --- git-prompt.sh | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/git-prompt.sh b/git-prompt.sh index adb6945..dea2967 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -1,6 +1,12 @@ # 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 + # 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 @@ -171,31 +177,26 @@ cwd_truncate() { # arg1: max path lenght # returns abbrivated $PWD in public "cwd" var - cwd=${PWD/$HOME/\~} # substitute "~" + cwd="${PWD/$HOME/~}" # substitute "~" case $1 in full) return ;; last) - cwd=${PWD##/*/} - [[ $PWD == $HOME ]] && cwd="~" + cwd="${PWD##/*/}" + [[ "$PWD" == "$HOME" ]] && cwd="~" return ;; *) - # if bash < v3.2 then don't truncate - if [[ ${BASH_VERSINFO[0]} -eq 3 && ${BASH_VERSINFO[1]} -le 1 || ${BASH_VERSINFO[0]} -lt 3 ]] ; then - return - fi ;; esac # split path into: head='~/', truncateble middle, last_dir local cwd_max_length=$1 - # expression which bash-3.1 or older can not understand, so we wrap it in eval - exp31='[[ "$cwd" =~ (~?/)(.*/)([^/]*)$ ]]' - if eval $exp31 ; then # only valid if path have more then 1 dir + + if [[ "$cwd" =~ '(~?/)(.*/)([^/]*)$' ]] ; then # only valid if path have more than 1 dir local path_head=${BASH_REMATCH[1]} local path_middle=${BASH_REMATCH[2]} local path_last_dir=${BASH_REMATCH[3]} @@ -211,8 +212,7 @@ cwd_truncate() { middle_tail=${path_middle:${#path_middle}-${cwd_middle_max}} # trunc on dir boundary (trunc 1st, probably tuncated dir) - exp31='[[ $middle_tail =~ [^/]*/(.*)$ ]]' - eval $exp31 + [[ $middle_tail =~ '[^/]*/(.*)$' ]] middle_tail=${BASH_REMATCH[1]} # use truncated only if we cut at least 4 chars -- cgit v1.2.3 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 From 6ecb1d4b9d52f60d63694aac39ebeb0940193b9f Mon Sep 17 00:00:00 2001 From: killphi Date: Thu, 19 Dec 2013 14:22:00 +0100 Subject: cleaned git-prompt.conf --- git-prompt.conf | 47 ++++++++++++++++++++++------------------------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/git-prompt.conf b/git-prompt.conf index dee3c0c..9b8a6fc 100644 --- a/git-prompt.conf +++ b/git-prompt.conf @@ -1,8 +1,5 @@ - ### GIT-PROMPT.SH CONFIG -### -### lines commented-out with single '#' are default values -### lines commented-out with double '##' are examples +### ### lines commented-out with single '#' are default values ### lines commented-out with double '##' are examples ### ### NOTE: this is bash syntax - no spaces around "=" @@ -25,9 +22,9 @@ ########################################################### DEFAULT OBJECTS ### Default objects are not displayed. Example: -## default_user=lvv +## default_user=lvv ## default_host="ahp" # remote host is always shown -## default_domain="lvvnet" +## default_domain="lvvnet" ########################################################### Current Working Dir display # cwd_cmd='\w' # display full path @@ -46,34 +43,34 @@ # they are always dirty (ex: home, /etc) or directory with huge repo (ex: linux src) ## vcs_ignore_dir_list=" /etc $HOME /usr/src/linux.git " -########################################################### COLOR +########################################################### COLOR -### directory, exit code, root color +### directory, exit code, root color # cols=`tput colors` -# if [[ -n "$cols" && $cols -ge 8 ]]; then # if terminal supports colors - # dir_color=CYAN - # rc_color=red - # virtualenv_color=green - # user_id_color=blue - # root_id_color=magenta +# if [[ -n "$cols" && $cols -ge 8 ]]; then # if terminal supports colors +# dir_color=CYAN +# rc_color=red +# virtualenv_color=green +# user_id_color=blue +# root_id_color=magenta # else # B/W terminal - # dir_color=bw_bold - # rc_color=bw_bold +# dir_color=bw_bold +# rc_color=bw_bold # fi ### prompt character for root/non-root, default '>' for both -# prompt_char='>' -# root_prompt_char='>' -## prompt_char='$' -## prompt_char='➔' -## root_prompt_char='#' +# prompt_char='>' +# root_prompt_char='>' +## prompt_char='$' +## prompt_char='➔' +## root_prompt_char='#' ##### Per host color ### Per host color. If not set, color will be derived from hostname checksum). ### Variable name is uppercase-short-hostname with appended "_host_color" -### Example per-host-color config: +### Example per-host-color config: ## TASHA_host_color=cyan ## AL_host_color=green @@ -86,11 +83,11 @@ # clean_vcs_color=blue # nothing to commit (working directory clean) # modified_vcs_color=red # Changed but not updated: # added_vcs_color=green # Changes to be committed: -# mixed_vcs_color=yellow # +# mixed_vcs_color=yellow # # untracked_vcs_color=BLUE # Untracked files: # op_vcs_color=MAGENTA # detached_vcs_color=RED -# hex_vcs_color=BLACK # git revision id: bright black (makes gray) +# hex_vcs_color=BLACK # git revision id: bright black (makes gray) -# :vim:ft=sh ts=8 sw=8 et: +# :vim:ft=sh ts=8 sts=8 sw=8 et: -- cgit v1.2.3 From 569178c05f02fa9f22a6fb7bd1baccf3765a866e Mon Sep 17 00:00:00 2001 From: killphi Date: Thu, 19 Dec 2013 14:24:24 +0100 Subject: retab on the rest of the files --- Makefile | 10 +++++----- demo-script | 14 +++++++------- index.txt | 40 ++++++++++++++++++++-------------------- 3 files changed, 32 insertions(+), 32 deletions(-) diff --git a/Makefile b/Makefile index 27631ce..e355689 100644 --- a/Makefile +++ b/Makefile @@ -12,10 +12,10 @@ COPY_LIST = git-prompt.sh install: - cp -v git-prompt.sh /etc/ - [ -f /etc/git-prompt.conf ] || cp -v git-prompt.conf /etc/ - + cp -v git-prompt.sh /etc/ + [ -f /etc/git-prompt.conf ] || cp -v git-prompt.conf /etc/ + tgit: - xclip -i git-demo - echo "ready to paste ..." + xclip -i git-demo + echo "ready to paste ..." diff --git a/demo-script b/demo-script index 1374a1f..ccd5019 100755 --- a/demo-script +++ b/demo-script @@ -2,7 +2,7 @@ cd p/git-prompt . ./git-prompt.sh cd test -d demo && rm -rf demo/ -test -d ../demo && cd .. && rm -rf demo/ +test -d ../demo && cd .. && rm -rf demo/ clear : ------------------------------------------------------------------------ clear @@ -15,21 +15,21 @@ touch untracked.o echo '*.o' >> .gitignore git commit -q -m "1st line" FOO git checkout -b test -echo "added 2nd line in test" >> FOO -git add FOO +echo "added 2nd line in test" >> FOO +git add FOO echo "2nd in BAR" > BAR git add BAR -echo "added 3nd line FOO" >> FOO +echo "added 3nd line FOO" >> FOO git add FOO git commit -q -m "FOO moded, BAR added" git checkout master -cat FOO -echo "now added 2nd line in master" >> FOO +cat FOO +echo "now added 2nd line in master" >> FOO git add FOO git commit -q -m "2nd line" git merge test git cat-file -p test:FOO > FOO -git add FOO +git add FOO git commit -q -m "merged" cat FOO git checkout HEAD^ diff --git a/index.txt b/index.txt index a48ab80..1ff5ab3 100644 --- a/index.txt +++ b/index.txt @@ -5,7 +5,7 @@ * Repo: httpx://github.com/lvv/scc[GitHub], httpx://bitbucket.org/lvv/scc[BitBucket] + * License: httpx://www.gnu.org/licenses/gpl-3.0.html[GPL3] -:v-p: http://volnitsky.com/project +:v-p: http://volnitsky.com/project :compact-option: compact @@ -20,7 +20,7 @@ terminal bell use `setterm`). == GIT -Branch and files are colored according to state. "M" stands for master. +Branch and files are colored according to state. "M" stands for master. image:screenshot-prompt-git.png[git module screenshot] @@ -33,16 +33,16 @@ image:screenshot-prompt-git.png[git module screenshot] | [darkred]#dark red# | [darkred]#dark red# | Modified and tracked by repo, but modifications not added to index yet. | [lightblue]#light blue# | [lightblue]#light blue# | Untracked file. | [red]#light red# | | Detached Head -| [magenta]#magenta# | | In middle of doing something +| [magenta]#magenta# | | In middle of doing something |================================================================ -== Subversion/SVN +== Subversion/SVN image:screenshot-svn.png[svn module screenshot] SVN module disabled by default because even on moderate sized working directories there is noticeable delay for prompt display. SVN is slower than -GIT. Enable if needed in <> +GIT. Enable if needed in <> == Mercurial/HG HG module was developed by Lee Nussbaum ``. @@ -78,12 +78,12 @@ session. It selects not most frequent dir, but last visited. Matches are done from beginning of of dir name (not path name). ----------------- -cd /tmp +cd /tmp cd "~/long dir mp3" cd "~/long dir mp4" cd /tmp cd /var/tmp -cd /etc +cd /etc cd j t # same as cd /var/tmp j .*3 # same as cd "~/long dir mp3" @@ -97,19 +97,19 @@ Download link:git-prompt.sh[] or get it with GIT: git clone git://github.com/lvv/git-prompt.git --------------- -Put following command at the end of your profile (`~/.bash_profile` or `~/.profile`) +Put following command at the end of your profile (`~/.bash_profile` or `~/.profile`) -------------------- [[ $- == *i* ]] && . /path/to/git-prompt.sh --------------------- -There might be your old prompt defined too. You can comment it out. +There might be your old prompt defined too. You can comment it out. Some distros also have `/etc/bashrc` or `/etc/bash/bashrc` with distro default prompt. -== GIT config +== GIT config GIT-PROMPT requires following GIT's option to be set: @@ -120,17 +120,17 @@ git config [--global] --unset i18n.logoutputencoding ----------------------------- -== GIT-PROMPT config +== GIT-PROMPT config [[config]] -Is optional. If config file is not found then git-prompt uses defaults. +Is optional. If config file is not found then git-prompt uses defaults. Defaults are listed in example `git-prompt.conf`. Git-prompt looks (in listed order) for config file in following locations: * `/etc/git-prompt.conf` * `~/.git-prompt.conf` -Copy example config `git-prompt.conf` +Copy example config `git-prompt.conf` to any of above locations and customize as needed. @@ -143,11 +143,11 @@ to any of above locations and customize as needed. you will maintain `.gitignore` and commit more often. * This prompt is most useful if your screen have enough width. If this is not the case, you might want to disable file list display (`max_file_list_length=0`). -* When prompt is longer than screen-width it wraps to second line. This is always undesirable. - Because of bug in `gnome-terminal` (or `readline` ?) some color escape codes can be visible on second line. +* When prompt is longer than screen-width it wraps to second line. This is always undesirable. + Because of bug in `gnome-terminal` (or `readline` ?) some color escape codes can be visible on second line. I've reported gnome-terminal bug. Again, you can disable file list display or limit length (`max_file_list_length`). * By default some terminals display ascii color with maximum color saturation - which makes colored text of different perceptual brightness. This makes it hard to read. + which makes colored text of different perceptual brightness. This makes it hard to read. If your terminal colors are configurable, try change it to softer (pastel) colors. @@ -155,9 +155,9 @@ to any of above locations and customize as needed. == Dependencies Most probably you don't need to install anything because not optional -dependencies are standard unix utils. +dependencies are standard unix utils. -* bash (tested with v3.2.33) +* bash (tested with v3.2.33) * sed * tput (terminfo) * tty (core utils) @@ -183,14 +183,14 @@ include::../volnitsky.com/project/howto-submit-patch.txt[] Nobody will use git-prompt if there will be delay in prompt display. Try to avoid use of external commands and subshells (backticks) in prompt_command_function. It is ok to use -time consuming ops in postconfig which is executed only once. +time consuming ops in postconfig which is executed only once. == Authors - Leonid Volnitsky (original author) , http://volnitsky.com - Niklas Hofer (CWD truncation) , httpx://github.com/niklas/[] - Lee Nussbaum (HG support) , httpx://github.com/wln[] - Albert Vernon http://xenoclub.wordpress.com[] -- Amir Yalon httpx://github.com/amiryal[] +- Amir Yalon httpx://github.com/amiryal[] - Martin httpx://github.com/jerrywho[] - Alexander Goldstein (emacs-shell, prompt chars) httpx://github.com/alexg0[] - Dmitry (bash completion) -- cgit v1.2.3 From bbac75bfa215cc07ad50db4670eebebeb5082ab4 Mon Sep 17 00:00:00 2001 From: Leonid Volnitsky Date: Thu, 19 Dec 2013 18:21:50 +0200 Subject: fixed: Makefile should have tabs --- Makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index e355689..4da74a6 100644 --- a/Makefile +++ b/Makefile @@ -12,10 +12,10 @@ COPY_LIST = git-prompt.sh install: - cp -v git-prompt.sh /etc/ - [ -f /etc/git-prompt.conf ] || cp -v git-prompt.conf /etc/ + cp -v git-prompt.sh /etc/ + [ -f /etc/git-prompt.conf ] || cp -v git-prompt.conf /etc/ tgit: - xclip -i git-demo - echo "ready to paste ..." + xclip -i git-demo + echo "ready to paste ..." -- cgit v1.2.3 From e7749248fd393aed48a6982ca9feeac7ef16c9d5 Mon Sep 17 00:00:00 2001 From: Leonid Volnitsky Date: Thu, 26 Dec 2013 19:45:28 +0200 Subject: Revert "fixed: Makefile should have tabs" This reverts commit bbac75bfa215cc07ad50db4670eebebeb5082ab4. --- Makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 4da74a6..e355689 100644 --- a/Makefile +++ b/Makefile @@ -12,10 +12,10 @@ COPY_LIST = git-prompt.sh install: - cp -v git-prompt.sh /etc/ - [ -f /etc/git-prompt.conf ] || cp -v git-prompt.conf /etc/ + cp -v git-prompt.sh /etc/ + [ -f /etc/git-prompt.conf ] || cp -v git-prompt.conf /etc/ tgit: - xclip -i git-demo - echo "ready to paste ..." + xclip -i git-demo + echo "ready to paste ..." -- cgit v1.2.3 From a279ba3d48f30e6fb117d76a106aba777cc218a8 Mon Sep 17 00:00:00 2001 From: Leonid Volnitsky Date: Thu, 26 Dec 2013 20:02:47 +0200 Subject: Revert "retab on the rest of the files" This reverts commit 569178c05f02fa9f22a6fb7bd1baccf3765a866e. --- Makefile | 10 +++++----- demo-script | 14 +++++++------- index.txt | 40 ++++++++++++++++++++-------------------- 3 files changed, 32 insertions(+), 32 deletions(-) diff --git a/Makefile b/Makefile index e355689..27631ce 100644 --- a/Makefile +++ b/Makefile @@ -12,10 +12,10 @@ COPY_LIST = git-prompt.sh install: - cp -v git-prompt.sh /etc/ - [ -f /etc/git-prompt.conf ] || cp -v git-prompt.conf /etc/ - + cp -v git-prompt.sh /etc/ + [ -f /etc/git-prompt.conf ] || cp -v git-prompt.conf /etc/ + tgit: - xclip -i git-demo - echo "ready to paste ..." + xclip -i git-demo + echo "ready to paste ..." diff --git a/demo-script b/demo-script index ccd5019..1374a1f 100755 --- a/demo-script +++ b/demo-script @@ -2,7 +2,7 @@ cd p/git-prompt . ./git-prompt.sh cd test -d demo && rm -rf demo/ -test -d ../demo && cd .. && rm -rf demo/ +test -d ../demo && cd .. && rm -rf demo/ clear : ------------------------------------------------------------------------ clear @@ -15,21 +15,21 @@ touch untracked.o echo '*.o' >> .gitignore git commit -q -m "1st line" FOO git checkout -b test -echo "added 2nd line in test" >> FOO -git add FOO +echo "added 2nd line in test" >> FOO +git add FOO echo "2nd in BAR" > BAR git add BAR -echo "added 3nd line FOO" >> FOO +echo "added 3nd line FOO" >> FOO git add FOO git commit -q -m "FOO moded, BAR added" git checkout master -cat FOO -echo "now added 2nd line in master" >> FOO +cat FOO +echo "now added 2nd line in master" >> FOO git add FOO git commit -q -m "2nd line" git merge test git cat-file -p test:FOO > FOO -git add FOO +git add FOO git commit -q -m "merged" cat FOO git checkout HEAD^ diff --git a/index.txt b/index.txt index 1ff5ab3..a48ab80 100644 --- a/index.txt +++ b/index.txt @@ -5,7 +5,7 @@ * Repo: httpx://github.com/lvv/scc[GitHub], httpx://bitbucket.org/lvv/scc[BitBucket] + * License: httpx://www.gnu.org/licenses/gpl-3.0.html[GPL3] -:v-p: http://volnitsky.com/project +:v-p: http://volnitsky.com/project :compact-option: compact @@ -20,7 +20,7 @@ terminal bell use `setterm`). == GIT -Branch and files are colored according to state. "M" stands for master. +Branch and files are colored according to state. "M" stands for master. image:screenshot-prompt-git.png[git module screenshot] @@ -33,16 +33,16 @@ image:screenshot-prompt-git.png[git module screenshot] | [darkred]#dark red# | [darkred]#dark red# | Modified and tracked by repo, but modifications not added to index yet. | [lightblue]#light blue# | [lightblue]#light blue# | Untracked file. | [red]#light red# | | Detached Head -| [magenta]#magenta# | | In middle of doing something +| [magenta]#magenta# | | In middle of doing something |================================================================ -== Subversion/SVN +== Subversion/SVN image:screenshot-svn.png[svn module screenshot] SVN module disabled by default because even on moderate sized working directories there is noticeable delay for prompt display. SVN is slower than -GIT. Enable if needed in <> +GIT. Enable if needed in <> == Mercurial/HG HG module was developed by Lee Nussbaum ``. @@ -78,12 +78,12 @@ session. It selects not most frequent dir, but last visited. Matches are done from beginning of of dir name (not path name). ----------------- -cd /tmp +cd /tmp cd "~/long dir mp3" cd "~/long dir mp4" cd /tmp cd /var/tmp -cd /etc +cd /etc cd j t # same as cd /var/tmp j .*3 # same as cd "~/long dir mp3" @@ -97,19 +97,19 @@ Download link:git-prompt.sh[] or get it with GIT: git clone git://github.com/lvv/git-prompt.git --------------- -Put following command at the end of your profile (`~/.bash_profile` or `~/.profile`) +Put following command at the end of your profile (`~/.bash_profile` or `~/.profile`) -------------------- [[ $- == *i* ]] && . /path/to/git-prompt.sh --------------------- -There might be your old prompt defined too. You can comment it out. +There might be your old prompt defined too. You can comment it out. Some distros also have `/etc/bashrc` or `/etc/bash/bashrc` with distro default prompt. -== GIT config +== GIT config GIT-PROMPT requires following GIT's option to be set: @@ -120,17 +120,17 @@ git config [--global] --unset i18n.logoutputencoding ----------------------------- -== GIT-PROMPT config +== GIT-PROMPT config [[config]] -Is optional. If config file is not found then git-prompt uses defaults. +Is optional. If config file is not found then git-prompt uses defaults. Defaults are listed in example `git-prompt.conf`. Git-prompt looks (in listed order) for config file in following locations: * `/etc/git-prompt.conf` * `~/.git-prompt.conf` -Copy example config `git-prompt.conf` +Copy example config `git-prompt.conf` to any of above locations and customize as needed. @@ -143,11 +143,11 @@ to any of above locations and customize as needed. you will maintain `.gitignore` and commit more often. * This prompt is most useful if your screen have enough width. If this is not the case, you might want to disable file list display (`max_file_list_length=0`). -* When prompt is longer than screen-width it wraps to second line. This is always undesirable. - Because of bug in `gnome-terminal` (or `readline` ?) some color escape codes can be visible on second line. +* When prompt is longer than screen-width it wraps to second line. This is always undesirable. + Because of bug in `gnome-terminal` (or `readline` ?) some color escape codes can be visible on second line. I've reported gnome-terminal bug. Again, you can disable file list display or limit length (`max_file_list_length`). * By default some terminals display ascii color with maximum color saturation - which makes colored text of different perceptual brightness. This makes it hard to read. + which makes colored text of different perceptual brightness. This makes it hard to read. If your terminal colors are configurable, try change it to softer (pastel) colors. @@ -155,9 +155,9 @@ to any of above locations and customize as needed. == Dependencies Most probably you don't need to install anything because not optional -dependencies are standard unix utils. +dependencies are standard unix utils. -* bash (tested with v3.2.33) +* bash (tested with v3.2.33) * sed * tput (terminfo) * tty (core utils) @@ -183,14 +183,14 @@ include::../volnitsky.com/project/howto-submit-patch.txt[] Nobody will use git-prompt if there will be delay in prompt display. Try to avoid use of external commands and subshells (backticks) in prompt_command_function. It is ok to use -time consuming ops in postconfig which is executed only once. +time consuming ops in postconfig which is executed only once. == Authors - Leonid Volnitsky (original author) , http://volnitsky.com - Niklas Hofer (CWD truncation) , httpx://github.com/niklas/[] - Lee Nussbaum (HG support) , httpx://github.com/wln[] - Albert Vernon http://xenoclub.wordpress.com[] -- Amir Yalon httpx://github.com/amiryal[] +- Amir Yalon httpx://github.com/amiryal[] - Martin httpx://github.com/jerrywho[] - Alexander Goldstein (emacs-shell, prompt chars) httpx://github.com/alexg0[] - Dmitry (bash completion) -- cgit v1.2.3 From c97179ba6c16ba64ac84c3ca54264faf9325ebb6 Mon Sep 17 00:00:00 2001 From: Leonid Volnitsky Date: Thu, 26 Dec 2013 20:03:05 +0200 Subject: Revert "cleaned git-prompt.conf" This reverts commit 6ecb1d4b9d52f60d63694aac39ebeb0940193b9f. --- git-prompt.conf | 47 +++++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/git-prompt.conf b/git-prompt.conf index 9b8a6fc..dee3c0c 100644 --- a/git-prompt.conf +++ b/git-prompt.conf @@ -1,5 +1,8 @@ + ### GIT-PROMPT.SH CONFIG -### ### lines commented-out with single '#' are default values ### lines commented-out with double '##' are examples +### +### lines commented-out with single '#' are default values +### lines commented-out with double '##' are examples ### ### NOTE: this is bash syntax - no spaces around "=" @@ -22,9 +25,9 @@ ########################################################### DEFAULT OBJECTS ### Default objects are not displayed. Example: -## default_user=lvv +## default_user=lvv ## default_host="ahp" # remote host is always shown -## default_domain="lvvnet" +## default_domain="lvvnet" ########################################################### Current Working Dir display # cwd_cmd='\w' # display full path @@ -43,34 +46,34 @@ # they are always dirty (ex: home, /etc) or directory with huge repo (ex: linux src) ## vcs_ignore_dir_list=" /etc $HOME /usr/src/linux.git " -########################################################### COLOR +########################################################### COLOR -### directory, exit code, root color +### directory, exit code, root color # cols=`tput colors` -# if [[ -n "$cols" && $cols -ge 8 ]]; then # if terminal supports colors -# dir_color=CYAN -# rc_color=red -# virtualenv_color=green -# user_id_color=blue -# root_id_color=magenta +# if [[ -n "$cols" && $cols -ge 8 ]]; then # if terminal supports colors + # dir_color=CYAN + # rc_color=red + # virtualenv_color=green + # user_id_color=blue + # root_id_color=magenta # else # B/W terminal -# dir_color=bw_bold -# rc_color=bw_bold + # dir_color=bw_bold + # rc_color=bw_bold # fi ### prompt character for root/non-root, default '>' for both -# prompt_char='>' -# root_prompt_char='>' -## prompt_char='$' -## prompt_char='➔' -## root_prompt_char='#' +# prompt_char='>' +# root_prompt_char='>' +## prompt_char='$' +## prompt_char='➔' +## root_prompt_char='#' ##### Per host color ### Per host color. If not set, color will be derived from hostname checksum). ### Variable name is uppercase-short-hostname with appended "_host_color" -### Example per-host-color config: +### Example per-host-color config: ## TASHA_host_color=cyan ## AL_host_color=green @@ -83,11 +86,11 @@ # clean_vcs_color=blue # nothing to commit (working directory clean) # modified_vcs_color=red # Changed but not updated: # added_vcs_color=green # Changes to be committed: -# mixed_vcs_color=yellow # +# mixed_vcs_color=yellow # # untracked_vcs_color=BLUE # Untracked files: # op_vcs_color=MAGENTA # detached_vcs_color=RED -# hex_vcs_color=BLACK # git revision id: bright black (makes gray) +# hex_vcs_color=BLACK # git revision id: bright black (makes gray) -# :vim:ft=sh ts=8 sts=8 sw=8 et: +# :vim:ft=sh ts=8 sw=8 et: -- cgit v1.2.3 From 682b3f48eb4c24ee5307dfe1f95973899f1016c1 Mon Sep 17 00:00:00 2001 From: Leonid Volnitsky Date: Thu, 26 Dec 2013 20:03:17 +0200 Subject: Revert "format consistently" This reverts commit 08f42056fd0e62ee53ab14b4fe95a2b5e04eed16. --- git-prompt.sh | 659 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 328 insertions(+), 331 deletions(-) diff --git a/git-prompt.sh b/git-prompt.sh index 2778d1f..dea2967 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} - -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 + ################# 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 - PS1="\w$prompt_char " - return 0 -fi -#################################################################### MARKERS -if [[ "$LC_CTYPE $LC_ALL" =~ "UTF" && $TERM != "linux" ]]; then - elipses_marker="…" -else - elipses_marker="..." -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 -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,101 +258,98 @@ 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 + 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 -if [[ "$TERM" = "screen" ]] ; then + # we don't need tty name under X11 + case $TERM in + xterm* | rxvt* | gnome-terminal | konsole | eterm* | wterm | cygwin) unset tty ;; + *);; + esac - # [ "$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` + 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 -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} + + 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" + # 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 - color_who_where="$user_id_color$color_who_where$colors_reset" -else - color_who_where='' -fi parse_svn_status() { @@ -363,27 +360,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() { @@ -396,12 +393,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` @@ -413,7 +410,7 @@ parse_hg_status() { if [[ "$bookmark" ]] ; then vcs_info+=/$bookmark fi -} + } @@ -430,9 +427,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 @@ -440,40 +437,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 @@ -506,7 +503,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)" @@ -517,8 +514,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 @@ -534,9 +531,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 @@ -551,14 +548,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() { @@ -582,10 +579,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 @@ -594,22 +591,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 @@ -641,30 +638,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 @@ -686,7 +683,7 @@ j (){ fi done echo '?' -} + } alias jumpstart='echo ${aj_dir_list[@]}' @@ -704,12 +701,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 @@ -719,12 +716,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 sts=8 sw=8 et: +# vim: set ft=sh ts=8 sw=8 et: -- cgit v1.2.3