summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2010-05-29 00:34:22 +0100
committerdakkar <dakkar@thenautilus.net>2010-05-29 00:34:22 +0100
commit3accf1ab1f6e2e67723e4618b25c6ee8a6339f03 (patch)
tree24a13412a5963e547c69d46ef628d6f3a8e52bc3
parentMerge branch 'master' into dakkar (diff)
downloadgit-prompt-3accf1ab1f6e2e67723e4618b25c6ee8a6339f03.tar.gz
git-prompt-3accf1ab1f6e2e67723e4618b25c6ee8a6339f03.tar.bz2
git-prompt-3accf1ab1f6e2e67723e4618b25c6ee8a6339f03.zip
s/``/"$()"/g — always show rc & jobs
-rwxr-xr-xgit-prompt.sh155
1 files changed, 67 insertions, 88 deletions
diff --git a/git-prompt.sh b/git-prompt.sh
index 0685d66..dc2a2d1 100755
--- a/git-prompt.sh
+++ b/git-prompt.sh
@@ -26,7 +26,7 @@
#### 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}
@@ -41,8 +41,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 state colors
init_vcs_color=${init_vcs_color:-WHITE} # initial
@@ -57,7 +57,7 @@
max_file_list_length=${max_file_list_length:-100}
upcase_hostname=${upcase_hostname:-on}
- aj_max=20
+ aj_max=${aj_max:-20}
##################################################################### post config
@@ -95,30 +95,30 @@
### 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`'\]' # why 14 doesn't work?
- WHITE='\['`tput setaf 7; tput bold`'\]'
-
- bw_bold='\['`tput 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)"'\]' # why 14 doesn't work?
+ WHITE='\['"$(tput setaf 7; 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}
@@ -142,7 +142,7 @@
#################################################################### MARKERS
screen_marker="sCRn"
- if [[ $LC_CTYPE =~ "UTF" && $TERM != "linux" ]]; then
+ if [[ $(locale|grep LC_CTYPE) =~ "UTF" && $TERM != "linux" ]]; then
elipses_marker="…"
else
elipses_marker="..."
@@ -157,14 +157,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
;;
@@ -178,13 +178,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
@@ -194,16 +194,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
@@ -243,13 +243,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
@@ -280,13 +280,13 @@ 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}
- #host=`hostname --short`
+ #host="$(hostname --short)"
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
@@ -294,7 +294,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%7}'`
+ cksum_color_no="$(echo $uphost | cksum | awk '{print $1%7}')"
color_index=(green yellow blue magenta cyan white) # FIXME: bw, color-256
host_color=${color_index[cksum_color_no]}
fi
@@ -335,23 +335,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
@@ -369,48 +369,29 @@ 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)"
[[ -z $modified ]] && [[ -z $untracked ]] && [[ -z $added ]] && clean=clean
vcs_info=${branch/default/D}
}
-parse_git_complete() {
- if [ "${BASH_VERSION%.*}" \< "3.0" ]; then
- # echo "You will need to upgrade 'bash' to version 3.0 \
- # for full programmable completion features (bash complete) \
- # Please install bash-completion packet like: $ yum -y install bash-completion"
- return
- fi
-
- complete -f -W "$(
- echo `git branch -a | sed -e s/[\ \*]//g | cut -f 1 -d ' ' | uniq`; \
- echo `git remote | sed -e s/[\ \*]//g | cut -f 1 -d ' ' | uniq`; \
- echo `git | tail -23 | head -21 | cut -d ' ' -f 4`; \
- echo '--help'; \
- echo '--staged'; \
- echo 'remote'; \
- echo 'help'; \
- )" g git
-}
-
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
@@ -501,12 +482,12 @@ parse_git_status() {
#### GET GIT HEX-REVISION
- rawhex=`git rev-parse HEAD 2>/dev/null`
- rawhex=${rawhex/HEAD/}
- rawhex=${rawhex:0:6}
+ rawhex="$(git rev-parse HEAD 2>/dev/null)"
+ rawhex="${rawhex/HEAD/}"
+ rawhex="${rawhex:0:6}"
#### branch
- branch=${branch/master/M}
+ 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; } )
@@ -519,7 +500,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
@@ -567,9 +548,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
@@ -615,8 +596,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
}
# autojump (see http://wiki.github.com/joelthelion/autojump)
@@ -640,13 +621,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_vcs_status
@@ -660,6 +637,8 @@ prompt_command_function() {
# else eval cwd_cmd, cwd should have path after exection
eval "${cwd_cmd/\\/cwd=\\\\}"
+ 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