diff options
-rw-r--r-- | color-test | 19 | ||||
-rwxr-xr-x | git-prompt.sh | 147 | ||||
-rw-r--r-- | upstream-remote | 1 |
3 files changed, 95 insertions, 72 deletions
diff --git a/color-test b/color-test new file mode 100644 index 0000000..4f30a0e --- /dev/null +++ b/color-test @@ -0,0 +1,19 @@ +#!/bin/bash +reset=`tput sgr0` +c=`tput sgr0; tput setaf 0`;echo "-black-${c}testTEST${reset}" +c=`tput sgr0; tput setaf 1`;echo "-red-${c}testTEST${reset}" +c=`tput sgr0; tput setaf 2`;echo "-green-${c}testTEST${reset}" +c=`tput sgr0; tput setaf 3`;echo "-yellow-${c}testTEST${reset}" +c=`tput sgr0; tput setaf 4`;echo "-blue-${c}testTEST${reset}" +c=`tput sgr0; tput setaf 5`;echo "-magenta-${c}testTEST${reset}" +c=`tput sgr0; tput setaf 6`;echo "-cyan-${c}testTEST${reset}" +c=`tput sgr0; tput setaf 7`;echo "-white-${c}testTEST${reset}" + +c=`tput setaf 0; tput bold`;echo "-BLACK-${c}testTEST${reset}" +c=`tput setaf 1; tput bold`;echo "-RED-${c}testTEST${reset}" +c=`tput setaf 2; tput bold`;echo "-GREEN-${c}testTEST${reset}" +c=`tput setaf 3; tput bold`;echo "-YELLOW-${c}testTEST${reset}" +c=`tput setaf 4; tput bold`;echo "-BLUE-${c}testTEST${reset}" +c=`tput setaf 5; tput bold`;echo "-MAGENTA-${c}testTEST${reset}" +c=`tput setaf 6; tput bold` # why 14 doesn't work?;echo "-CYAN-${c}testTEST${reset}" +c=`tput setaf 7; tput bold`;echo "-WHITE-${c}testTEST${reset}" diff --git a/git-prompt.sh b/git-prompt.sh index f99a1d0..3fac2f0 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -5,7 +5,7 @@ ##### read config file if any. - unset dir_color rc_color user_id_color root_id_color init_vcs_color clean_vcs_color + unset dir_color rc_color jobs_color prompt_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 @@ -28,10 +28,12 @@ #### dir, rc, root color - cols=`tput colors` # in emacs shell-mode tput colors returns -1 + 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} + jobs_color=${jobs_color:-cyan} + prompt_color=${prompt_color:-CYAN} virtualenv_color=${virtualenv_color:-green} user_id_color=${user_id_color:-blue} root_id_color=${root_id_color:-magenta} @@ -42,8 +44,8 @@ unset cols #### prompt character, for root/non-root - prompt_char=${prompt_char:-'>'} - root_prompt_char=${root_prompt_char:-'>'} + prompt_char="${prompt_char:-'>'}" + root_prompt_char="${root_prompt_char:-'>'}" #### vcs colors init_vcs_color=${init_vcs_color:-WHITE} # initial @@ -64,7 +66,7 @@ count_only=${count_only:-off} rawhex_len=${rawhex_len:-5} - aj_max=20 + aj_max=${aj_max:-20} ##################################################################### post config @@ -102,32 +104,32 @@ ### 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 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`'\]' + 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 + dim='\['"$(tput sgr0; tput setaf p1)"'\]' # half-bright - bw_bold='\['`tput bold`'\]' + bw_bold='\['"$(tput bold)"'\]' on='' off=': ' - bell="\[`eval ${!error_bell} tput bel`\]" - colors_reset='\['`tput sgr0`'\]' + bell="\["$(eval ${!error_bell} tput bel)"\]" + colors_reset='\['"$(tput sgr0)"'\]' # replace symbolic colors names to raw treminfo strings init_vcs_color=${!init_vcs_color} @@ -151,6 +153,7 @@ fi #################################################################### MARKERS + screen_marker="sCRn" if [[ "$LC_CTYPE $LC_ALL" =~ "UTF" && $TERM != "linux" ]]; then elipses_marker="…" else @@ -166,14 +169,14 @@ 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##/*/} + cwd="${PWD##/*/}" [[ $PWD == $HOME ]] && cwd="~" return ;; @@ -187,13 +190,13 @@ cwd_truncate() { # split path into: head='~/', truncateble middle, last_dir - local cwd_max_length=$1 + 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 - local path_head=${BASH_REMATCH[1]} - local path_middle=${BASH_REMATCH[2]} - local path_last_dir=${BASH_REMATCH[3]} + local path_head="${BASH_REMATCH[1]}" + local path_middle="${BASH_REMATCH[2]}" + local path_last_dir="${BASH_REMATCH[3]}" local cwd_middle_max=$(( $cwd_max_length - ${#path_last_dir} )) [[ $cwd_middle_max < 0 ]] && cwd_middle_max=0 @@ -203,16 +206,16 @@ cwd_truncate() { if [[ ${#path_middle} -gt $(( $cwd_middle_max + ${#elipses_marker} + 5 )) ]]; then # truncate - middle_tail=${path_middle:${#path_middle}-${cwd_middle_max}} + 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=${BASH_REMATCH[1]} + 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 + cwd="$path_head$elipses_marker$middle_tail$path_last_dir" fi fi fi @@ -229,7 +232,7 @@ set_shell_label() { screen_label() { # FIXME: run this only if screen is in xterm (how to test for this?) - xterm_label "$plain_who_where $@" + xterm_label "$screen_marker $plain_who_where $@" # FIXME $STY not inherited though "su -" [ "$STY" ] && screen -S $STY -X title "$*" @@ -258,13 +261,13 @@ 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 @@ -284,6 +287,8 @@ set_shell_label() { dir_color=${!dir_color} rc_color=${!rc_color} + prompt_color=${!prompt_color} + jobs_color=${!jobs_color} virtualenv_color=${!virtualenv_color} user_id_color=${!user_id_color} root_id_color=${!root_id_color} @@ -294,19 +299,19 @@ set_shell_label() { # 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 ==; } + # 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` + host="$(hostname)" else - host=`hostname -s` + host="$(hostname -s)" fi fi host=${host#$default_host} - uphost=`echo ${host} | tr a-z-. A-Z_` + uphost="$(echo ${host} | tr a-z-. A-Z_)" if [[ $upcase_hostname = "on" ]]; then host=${uphost} fi @@ -314,7 +319,7 @@ set_shell_label() { 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}'` + 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 @@ -326,11 +331,11 @@ set_shell_label() { #################################################################### WHO_WHERE # [[user@]host[-tty]] - - if [[ -n $id || -n $host ]] ; then + + if [[ -n $id || -n $host || -n $special_env ]] ; then [[ -n $id && -n $host ]] && at='@' || at='' - color_who_where="${id}${host:+$host_color$at$host}${tty:+ $tty}" - plain_who_where="${id}$at$host" + color_who_where="${special_env:+($special_env) }${id}${host:+$host_color$at$host}${tty:+ $tty}" + plain_who_where="${special_env:+($special_env) }${id}$at$host" # add trailing " " color_who_where="$color_who_where " @@ -354,23 +359,23 @@ parse_svn_status() { vcs=svn ### get rev - eval ` + eval "$( 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 | + 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 ' - ` + )" # TODO branch detection if standard repo layout [[ -z $modified ]] && [[ -z $untracked ]] && clean=clean @@ -387,16 +392,16 @@ parse_hg_status() { ### get status unset status modified added clean init added mixed untracked op detached - eval `hg status 2>/dev/null | + 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 - '` + ')" - branch=`hg branch 2> /dev/null` + branch="$(hg branch 2> /dev/null)" [[ -f $hg_root/.hg/bookmarks.current ]] && bookmark=`cat "$hg_root/.hg/bookmarks.current"` @@ -413,9 +418,9 @@ parse_git_status() { # TODO add status: LOCKED (.git/index.lock) - git_dir=`[[ $git_module = "on" ]] && git rev-parse --git-dir 2> /dev/null` - #git_dir=`eval \$$git_module git rev-parse --git-dir 2> /dev/null` - #git_dir=` git rev-parse --git-dir 2> /dev/null` + git_dir="$([[ $git_module = "on" ]] && git rev-parse --git-dir 2> /dev/null)" + #git_dir="$(eval \$$git_module git rev-parse --git-dir 2> /dev/null)" + #git_dir="$( git rev-parse --git-dir 2> /dev/null)" [[ -n ${git_dir/./} ]] || return 1 @@ -513,7 +518,7 @@ parse_git_status() { #### GET GIT HEX-REVISION if [[ $rawhex_len -gt 0 ]] ; then - rawhex=`git rev-parse HEAD 2>/dev/null` + rawhex="$(git rev-parse HEAD 2>/dev/null)" rawhex=${rawhex/HEAD/} rawhex="$hex_vcs_color${rawhex:0:$rawhex_len}" else @@ -534,7 +539,7 @@ parse_git_status() { else if [[ "$detached" ]] ; then - branch="<detached:`git name-rev --name-only HEAD 2>/dev/null`" + branch="<detached:$(git name-rev --name-only HEAD 2>/dev/null)" elif [[ "$op" ]]; then @@ -582,9 +587,9 @@ parse_vcs_status() { if [[ $vim_module = "on" ]] ; then # equivalent to vim_glob=`ls .*.vim` but without running ls unset vim_glob vim_file vim_files - old_nullglob=`shopt -p nullglob` + old_nullglob="$(shopt -p nullglob)" shopt -s nullglob - vim_glob=`echo .*.sw?` + vim_glob="$(echo .*.sw?)" eval $old_nullglob if [[ $vim_glob ]]; then @@ -651,8 +656,8 @@ disable_set_shell_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 - trap '[[ -z "$BASH_SOURCE" && ($BASH_COMMAND != prompt_command_function) ]] && - set_shell_label $BASH_COMMAND' DEBUG >& /dev/null + trap '[[ "$BASH_COMMAND" != prompt_command_function ]] && + set_shell_label "$BASH_COMMAND"' DEBUG >& /dev/null } declare -ft disable_set_shell_label @@ -684,13 +689,9 @@ alias jumpstart='echo ${aj_dir_list[@]}' prompt_command_function() { rc="$?" - if [[ "$rc" == "0" ]]; then - rc="" - else - rc="$rc_color$rc$colors_reset$bell " - fi + rc="$rc_color($rc)$colors_reset" - cwd=${PWD/$HOME/\~} # substitute "~" + cwd="${PWD/$HOME/~}" # substitute "~" set_shell_label "${cwd##[/~]*/}/" # default label - path last dir parse_virtualenv_status @@ -705,7 +706,9 @@ prompt_command_function() { # else eval cwd_cmd, cwd should have path after exection eval "${cwd_cmd/\\/cwd=\\\\}" - PS1="$colors_reset$rc$head_local$color_who_where$dir_color$cwd$tail_local$dir_color$prompt_char $colors_reset" + jobs="$jobs_color[\j]$jobs_color" + + PS1="$colors_reset$color_who_where$dir_color$cwd $head_local\n$colors_reset$rc$jobs$prompt_color$prompt_char $colors_reset" unset head_local tail_local pwd } diff --git a/upstream-remote b/upstream-remote new file mode 100644 index 0000000..41d86c0 --- /dev/null +++ b/upstream-remote @@ -0,0 +1 @@ +origin git://github.com/lvv/git-prompt.git |