Remove tabs

This commit is contained in:
Michael Campagnaro 2015-11-21 13:29:44 -05:00
parent 08276cb5c7
commit 910412c6a4
3 changed files with 559 additions and 565 deletions

View File

@ -1,6 +1,5 @@
# grb prompt theme # grb prompt theme
# copied from wunjo prompt theme and modified # copied from wunjo prompt theme and modified
autoload -U zgitinit autoload -U zgitinit
zgitinit zgitinit
@ -13,32 +12,32 @@ EOF
} }
revstring() { revstring() {
git describe --always $1 2>/dev/null || git describe --always $1 2>/dev/null ||
git rev-parse --short $1 2>/dev/null git rev-parse --short $1 2>/dev/null
} }
coloratom() { coloratom() {
local off=$1 atom=$2 local off=$1 atom=$2
if [[ $atom[1] == [[:upper:]] ]]; then if [[ $atom[1] == [[:upper:]] ]]; then
off=$(( $off + 60 )) off=$(( $off + 60 ))
fi fi
echo $(( $off + $colorcode[${(L)atom}] )) echo $(( $off + $colorcode[${(L)atom}] ))
} }
colorword() { colorword() {
local fg=$1 bg=$2 att=$3 local fg=$1 bg=$2 att=$3
local -a s local -a s
if [ -n "$fg" ]; then if [ -n "$fg" ]; then
s+=$(coloratom 30 $fg) s+=$(coloratom 30 $fg)
fi fi
if [ -n "$bg" ]; then if [ -n "$bg" ]; then
s+=$(coloratom 40 $bg) s+=$(coloratom 40 $bg)
fi fi
if [ -n "$att" ]; then if [ -n "$att" ]; then
s+=$attcode[$att] s+=$attcode[$att]
fi fi
echo "%{"$'\e['${(j:;:)s}m"%}" echo "%{"$'\e['${(j:;:)s}m"%}"
} }
function minutes_since_last_commit { function minutes_since_last_commit {
@ -54,14 +53,14 @@ function minutes_since_last_commit {
} }
function prompt_grb_scm_time_since_commit() { function prompt_grb_scm_time_since_commit() {
local -A pc local -A pc
pc=(${(kv)wunjo_prompt_colors}) pc=(${(kv)wunjo_prompt_colors})
if zgit_inworktree; then if zgit_inworktree; then
local MINUTES_SINCE_LAST_COMMIT=`minutes_since_last_commit` local MINUTES_SINCE_LAST_COMMIT=`minutes_since_last_commit`
if [ "$MINUTES_SINCE_LAST_COMMIT" -eq -1 ]; then if [ "$MINUTES_SINCE_LAST_COMMIT" -eq -1 ]; then
COLOR="$pc[scm_time_uncommitted]" COLOR="$pc[scm_time_uncommitted]"
local SINCE_LAST_COMMIT="${COLOR}uncommitted$pc[reset]" local SINCE_LAST_COMMIT="${COLOR}uncommitted$pc[reset]"
else else
if [ "$MINUTES_SINCE_LAST_COMMIT" -gt 30 ]; then if [ "$MINUTES_SINCE_LAST_COMMIT" -gt 30 ]; then
COLOR="$pc[scm_time_long]" COLOR="$pc[scm_time_long]"
@ -89,7 +88,7 @@ prompt_grb_setup() {
else else
verbose=1 verbose=1
fi fi
typeset -A colorcode typeset -A colorcode
colorcode[black]=0 colorcode[black]=0
colorcode[red]=1 colorcode[red]=1
@ -109,7 +108,7 @@ prompt_grb_setup() {
colorcode[c]=$colorcode[cyan] colorcode[c]=$colorcode[cyan]
colorcode[w]=$colorcode[white] colorcode[w]=$colorcode[white]
colorcode[.]=$colorcode[default] colorcode[.]=$colorcode[default]
typeset -A attcode typeset -A attcode
attcode[none]=00 attcode[none]=00
attcode[bold]=01 attcode[bold]=01
@ -125,7 +124,7 @@ prompt_grb_setup() {
attcode[no-blink]=25 attcode[no-blink]=25
attcode[no-reverse]=27 attcode[no-reverse]=27
attcode[no-conceal]=28 attcode[no-conceal]=28
local -A pc local -A pc
pc[divider]='black' pc[divider]='black'
pc[default]='default' pc[default]='default'
@ -153,190 +152,188 @@ prompt_grb_setup() {
done done
pc[reset]=$(colorword . . 00) pc[reset]=$(colorword . . 00)
typeset -Ag wunjo_prompt_colors typeset -Ag wunjo_prompt_colors
wunjo_prompt_colors=(${(kv)pc}) wunjo_prompt_colors=(${(kv)pc})
local p_date p_line p_rc local p_date p_line p_rc
p_date="$pc[date]%D{%Y-%m-%d} $pc[time]%D{%T}$pc[reset]" p_date="$pc[date]%D{%Y-%m-%d} $pc[time]%D{%T}$pc[reset]"
p_line="$pc[line]%y$pc[reset]" p_line="$pc[line]%y$pc[reset]"
PROMPT="$pc[divider]\$(repeat \$COLUMNS printf '-')$pc[reset]" PROMPT="$pc[divider]\$(repeat \$COLUMNS printf '-')$pc[reset]"
PROMPT+= PROMPT+=
if [ $verbose ]; then if [ $verbose ]; then
PROMPT+="$pc[host]%m$pc[reset]" PROMPT+="$pc[host]%m$pc[reset]"
fi fi
#PROMPT+="$pc[path]%(2~.%~.%/)$pc[reset]" #PROMPT+="$pc[path]%(2~.%~.%/)$pc[reset]"
#PROMPT+="\$(prompt_wunjo_scm_status)" #PROMPT+="\$(prompt_wunjo_scm_status)"
#PROMPT+="%(?.. $pc[rc]exited %1v$pc[reset])" #PROMPT+="%(?.. $pc[rc]exited %1v$pc[reset])"
# PROMPT+=" # PROMPT+="
#" #"
#PROMPT+="($pc[hist]%h$pc[reset])" #PROMPT+="($pc[hist]%h$pc[reset])"
PROMPT+=":$pc[shortpath]%1~$pc[reset]" PROMPT+=":$pc[shortpath]%1~$pc[reset]"
PROMPT+="($pc[scm_branch]\$(prompt_wunjo_scm_branch)$pc[reset])" PROMPT+="($pc[scm_branch]\$(prompt_wunjo_scm_branch)$pc[reset])"
PROMPT+=" $pc[#]\$$pc[reset] " PROMPT+=" $pc[#]\$$pc[reset] "
#RPROMPT= #RPROMPT=
#if [ $verbose ]; then #if [ $verbose ]; then
# RPROMPT+="$p_date " # RPROMPT+="$p_date "
#fi #fi
#RPROMPT+="$pc[user]%n$pc[reset]" #RPROMPT+="$pc[user]%n$pc[reset]"
#RPROMPT+=" $p_line" #RPROMPT+=" $p_line"
export PROMPT RPROMPT export PROMPT RPROMPT
precmd_functions+='prompt_wunjo_precmd' precmd_functions+='prompt_wunjo_precmd'
} }
prompt_wunjo_precmd() { prompt_wunjo_precmd() {
local ex=$? local ex=$?
psvar=() psvar=()
if [[ $ex -ge 128 ]]; then if [[ $ex -ge 128 ]]; then
sig=$signals[$ex-127] sig=$signals[$ex-127]
psvar[1]="sig${(L)sig}" psvar[1]="sig${(L)sig}"
else else
psvar[1]="$ex" psvar[1]="$ex"
fi fi
} }
prompt_wunjo_scm_status() { prompt_wunjo_scm_status() {
zgit_isgit || return zgit_isgit || return
local -A pc local -A pc
pc=(${(kv)wunjo_prompt_colors}) pc=(${(kv)wunjo_prompt_colors})
head=$(zgit_head) head=$(zgit_head)
gitcommit=$(revstring $head) gitcommit=$(revstring $head)
local -a commits local -a commits
if zgit_rebaseinfo; then if zgit_rebaseinfo; then
orig_commit=$(revstring $zgit_info[rb_head]) orig_commit=$(revstring $zgit_info[rb_head])
orig_name=$(git name-rev --name-only $zgit_info[rb_head]) orig_name=$(git name-rev --name-only $zgit_info[rb_head])
orig="$pc[scm_branch]$orig_name$pc[punc]($pc[scm_commitid]$orig_commit$pc[punc])" orig="$pc[scm_branch]$orig_name$pc[punc]($pc[scm_commitid]$orig_commit$pc[punc])"
onto_commit=$(revstring $zgit_info[rb_onto]) onto_commit=$(revstring $zgit_info[rb_onto])
onto_name=$(git name-rev --name-only $zgit_info[rb_onto]) onto_name=$(git name-rev --name-only $zgit_info[rb_onto])
onto="$pc[scm_branch]$onto_name$pc[punc]($pc[scm_commitid]$onto_commit$pc[punc])" onto="$pc[scm_branch]$onto_name$pc[punc]($pc[scm_commitid]$onto_commit$pc[punc])"
if [ -n "$zgit_info[rb_upstream]" ] && [ $zgit_info[rb_upstream] != $zgit_info[rb_onto] ]; then if [ -n "$zgit_info[rb_upstream]" ] && [ $zgit_info[rb_upstream] != $zgit_info[rb_onto] ]; then
upstream_commit=$(revstring $zgit_info[rb_upstream]) upstream_commit=$(revstring $zgit_info[rb_upstream])
upstream_name=$(git name-rev --name-only $zgit_info[rb_upstream]) upstream_name=$(git name-rev --name-only $zgit_info[rb_upstream])
upstream="$pc[scm_branch]$upstream_name$pc[punc]($pc[scm_commitid]$upstream_commit$pc[punc])" upstream="$pc[scm_branch]$upstream_name$pc[punc]($pc[scm_commitid]$upstream_commit$pc[punc])"
commits+="rebasing $upstream$pc[reset]..$orig$pc[reset] onto $onto$pc[reset]" commits+="rebasing $upstream$pc[reset]..$orig$pc[reset] onto $onto$pc[reset]"
else else
commits+="rebasing $onto$pc[reset]..$orig$pc[reset]" commits+="rebasing $onto$pc[reset]..$orig$pc[reset]"
fi fi
local -a revs local -a revs
revs=($(git rev-list $zgit_info[rb_onto]..HEAD)) revs=($(git rev-list $zgit_info[rb_onto]..HEAD))
if [ $#revs -gt 0 ]; then if [ $#revs -gt 0 ]; then
commits+="\n$#revs commits in" commits+="\n$#revs commits in"
fi fi
if [ -f $zgit_info[dotest]/message ]; then if [ -f $zgit_info[dotest]/message ]; then
mess=$(head -n1 $zgit_info[dotest]/message) mess=$(head -n1 $zgit_info[dotest]/message)
commits+="on $mess" commits+="on $mess"
fi fi
elif [ -n "$gitcommit" ]; then elif [ -n "$gitcommit" ]; then
commits+="on $pc[scm_branch]$head$pc[punc]($pc[scm_commitid]$gitcommit$pc[punc])$pc[reset]" commits+="on $pc[scm_branch]$head$pc[punc]($pc[scm_commitid]$gitcommit$pc[punc])$pc[reset]"
local track_merge=$(zgit_tracking_merge) local track_merge=$(zgit_tracking_merge)
if [ -n "$track_merge" ]; then if [ -n "$track_merge" ]; then
if git rev-parse --verify -q $track_merge >/dev/null; then if git rev-parse --verify -q $track_merge >/dev/null; then
local track_remote=$(zgit_tracking_remote) local track_remote=$(zgit_tracking_remote)
local tracked=$(revstring $track_merge 2>/dev/null) local tracked=$(revstring $track_merge 2>/dev/null)
local -a revs local -a revs
revs=($(git rev-list --reverse $track_merge..HEAD)) revs=($(git rev-list --reverse $track_merge..HEAD))
if [ $#revs -gt 0 ]; then if [ $#revs -gt 0 ]; then
local base=$(revstring $revs[1]~1) local base=$(revstring $revs[1]~1)
local base_name=$(git name-rev --name-only $base) local base_name=$(git name-rev --name-only $base)
local base_short=$(revstring $base) local base_short=$(revstring $base)
local word_commits local word_commits
if [ $#revs -gt 1 ]; then if [ $#revs -gt 1 ]; then
word_commits='commits' word_commits='commits'
else else
word_commits='commit' word_commits='commit'
fi fi
local conj="since" local conj="since"
if [[ "$base" == "$tracked" ]]; then if [[ "$base" == "$tracked" ]]; then
conj+=" tracked" conj+=" tracked"
tracked= tracked=
fi fi
commits+="$#revs $word_commits $conj $pc[scm_branch]$base_name$pc[punc]($pc[scm_commitid]$base_short$pc[punc])$pc[reset]" commits+="$#revs $word_commits $conj $pc[scm_branch]$base_name$pc[punc]($pc[scm_commitid]$base_short$pc[punc])$pc[reset]"
fi fi
if [ -n "$tracked" ]; then if [ -n "$tracked" ]; then
local track_name=$track_merge local track_name=$track_merge
if [[ $track_remote == "." ]]; then if [[ $track_remote == "." ]]; then
track_name=${track_name##*/} track_name=${track_name##*/}
fi fi
tracked=$(revstring $tracked) tracked=$(revstring $tracked)
commits+="tracking $pc[scm_branch]$track_name$pc[punc]" commits+="tracking $pc[scm_branch]$track_name$pc[punc]"
if [[ "$tracked" != "$gitcommit" ]]; then if [[ "$tracked" != "$gitcommit" ]]; then
commits[$#commits]+="($pc[scm_commitid]$tracked$pc[punc])" commits[$#commits]+="($pc[scm_commitid]$tracked$pc[punc])"
fi fi
commits[$#commits]+="$pc[reset]" commits[$#commits]+="$pc[reset]"
fi fi
fi fi
fi fi
fi fi
gitsvn=$(git rev-parse --verify -q --short git-svn) gitsvn=$(git rev-parse --verify -q --short git-svn)
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
gitsvnrev=$(zgit_svnhead $gitsvn) gitsvnrev=$(zgit_svnhead $gitsvn)
gitsvn=$(revstring $gitsvn) gitsvn=$(revstring $gitsvn)
if [ -n "$gitsvnrev" ]; then if [ -n "$gitsvnrev" ]; then
local svninfo='' local svninfo=''
local -a revs local -a revs
svninfo+="$pc[default]svn$pc[punc]:$pc[scm_branch]r$gitsvnrev" svninfo+="$pc[default]svn$pc[punc]:$pc[scm_branch]r$gitsvnrev"
revs=($(git rev-list git-svn..HEAD)) revs=($(git rev-list git-svn..HEAD))
if [ $#revs -gt 0 ]; then if [ $#revs -gt 0 ]; then
svninfo+="$pc[punc]@$pc[default]HEAD~$#revs" svninfo+="$pc[punc]@$pc[default]HEAD~$#revs"
svninfo+="$pc[punc]($pc[scm_commitid]$gitsvn$pc[punc])" svninfo+="$pc[punc]($pc[scm_commitid]$gitsvn$pc[punc])"
fi fi
commits+=$svninfo commits+=$svninfo
fi fi
fi fi
if [ $#commits -gt 0 ]; then if [ $#commits -gt 0 ]; then
echo -n " ${(j: :)commits}" echo -n " ${(j: :)commits}"
fi fi
} }
prompt_wunjo_scm_branch() { prompt_wunjo_scm_branch() {
zgit_isgit || return zgit_isgit || return
local -A pc local -A pc
pc=(${(kv)wunjo_prompt_colors}) pc=(${(kv)wunjo_prompt_colors})
echo -n "$pc[punc]$pc[scm_branch]$(zgit_head)" echo -n "$pc[punc]$pc[scm_branch]$(zgit_head)"
if zgit_inworktree; then if zgit_inworktree; then
if ! zgit_isindexclean; then if ! zgit_isindexclean; then
echo -n "$pc[scm_status_staged]+" echo -n "$pc[scm_status_staged]+"
fi fi
local -a dirty local -a dirty
if ! zgit_isworktreeclean; then if ! zgit_isworktreeclean; then
dirty+='!' dirty+='!'
fi fi
if zgit_hasunmerged; then if zgit_hasunmerged; then
dirty+='*' dirty+='*'
fi fi
if zgit_hasuntracked; then if zgit_hasuntracked; then
dirty+='?' dirty+='?'
fi fi
if [ $#dirty -gt 0 ]; then if [ $#dirty -gt 0 ]; then
echo -n "$pc[scm_status_dirty]${(j::)dirty}" echo -n "$pc[scm_status_dirty]${(j::)dirty}"
fi fi
fi fi
echo $pc[reset] echo $pc[reset]
} }
prompt_grb_setup "$@" prompt_grb_setup "$@"
# vim:set ft=zsh:

View File

@ -12,281 +12,281 @@ EOF
} }
revstring() { revstring() {
git describe --always $1 2>/dev/null || git describe --always $1 2>/dev/null ||
git rev-parse --short $1 2>/dev/null git rev-parse --short $1 2>/dev/null
} }
coloratom() { coloratom() {
local off=$1 atom=$2 local off=$1 atom=$2
if [[ $atom[1] == [[:upper:]] ]]; then if [[ $atom[1] == [[:upper:]] ]]; then
off=$(( $off + 60 )) off=$(( $off + 60 ))
fi fi
echo $(( $off + $colorcode[${(L)atom}] )) echo $(( $off + $colorcode[${(L)atom}] ))
} }
colorword() { colorword() {
local fg=$1 bg=$2 att=$3 local fg=$1 bg=$2 att=$3
local -a s local -a s
if [ -n "$fg" ]; then if [ -n "$fg" ]; then
s+=$(coloratom 30 $fg) s+=$(coloratom 30 $fg)
fi fi
if [ -n "$bg" ]; then if [ -n "$bg" ]; then
s+=$(coloratom 40 $bg) s+=$(coloratom 40 $bg)
fi fi
if [ -n "$att" ]; then if [ -n "$att" ]; then
s+=$attcode[$att] s+=$attcode[$att]
fi fi
echo "%{"$'\e['${(j:;:)s}m"%}" echo "%{"$'\e['${(j:;:)s}m"%}"
} }
prompt_wunjo_setup() { prompt_wunjo_setup() {
local verbose local verbose
if [[ $TERM == screen* ]] && [ -n "$STY" ]; then if [[ $TERM == screen* ]] && [ -n "$STY" ]; then
verbose= verbose=
else else
verbose=1 verbose=1
fi fi
typeset -A colorcode typeset -A colorcode
colorcode[black]=0 colorcode[black]=0
colorcode[red]=1 colorcode[red]=1
colorcode[green]=2 colorcode[green]=2
colorcode[yellow]=3 colorcode[yellow]=3
colorcode[blue]=4 colorcode[blue]=4
colorcode[magenta]=5 colorcode[magenta]=5
colorcode[cyan]=6 colorcode[cyan]=6
colorcode[white]=7 colorcode[white]=7
colorcode[default]=9 colorcode[default]=9
colorcode[k]=$colorcode[black] colorcode[k]=$colorcode[black]
colorcode[r]=$colorcode[red] colorcode[r]=$colorcode[red]
colorcode[g]=$colorcode[green] colorcode[g]=$colorcode[green]
colorcode[y]=$colorcode[yellow] colorcode[y]=$colorcode[yellow]
colorcode[b]=$colorcode[blue] colorcode[b]=$colorcode[blue]
colorcode[m]=$colorcode[magenta] colorcode[m]=$colorcode[magenta]
colorcode[c]=$colorcode[cyan] colorcode[c]=$colorcode[cyan]
colorcode[w]=$colorcode[white] colorcode[w]=$colorcode[white]
colorcode[.]=$colorcode[default] colorcode[.]=$colorcode[default]
typeset -A attcode typeset -A attcode
attcode[none]=00 attcode[none]=00
attcode[bold]=01 attcode[bold]=01
attcode[faint]=02 attcode[faint]=02
attcode[standout]=03 attcode[standout]=03
attcode[underline]=04 attcode[underline]=04
attcode[blink]=05 attcode[blink]=05
attcode[reverse]=07 attcode[reverse]=07
attcode[conceal]=08 attcode[conceal]=08
attcode[normal]=22 attcode[normal]=22
attcode[no-standout]=23 attcode[no-standout]=23
attcode[no-underline]=24 attcode[no-underline]=24
attcode[no-blink]=25 attcode[no-blink]=25
attcode[no-reverse]=27 attcode[no-reverse]=27
attcode[no-conceal]=28 attcode[no-conceal]=28
local -A pc local -A pc
pc[default]='default' pc[default]='default'
pc[date]='cyan' pc[date]='cyan'
pc[time]='Blue' pc[time]='Blue'
pc[host]='Green' pc[host]='Green'
pc[user]='cyan' pc[user]='cyan'
pc[punc]='yellow' pc[punc]='yellow'
pc[line]='magenta' pc[line]='magenta'
pc[hist]='green' pc[hist]='green'
pc[path]='Cyan' pc[path]='Cyan'
pc[shortpath]='default' pc[shortpath]='default'
pc[rc]='red' pc[rc]='red'
pc[scm_branch]='Cyan' pc[scm_branch]='Cyan'
pc[scm_commitid]='Yellow' pc[scm_commitid]='Yellow'
pc[scm_status_dirty]='Red' pc[scm_status_dirty]='Red'
pc[scm_status_staged]='Green' pc[scm_status_staged]='Green'
pc[#]='Yellow' pc[#]='Yellow'
for cn in ${(k)pc}; do for cn in ${(k)pc}; do
pc[${cn}]=$(colorword $pc[$cn]) pc[${cn}]=$(colorword $pc[$cn])
done done
pc[reset]=$(colorword . . 00) pc[reset]=$(colorword . . 00)
typeset -Ag wunjo_prompt_colors typeset -Ag wunjo_prompt_colors
wunjo_prompt_colors=(${(kv)pc}) wunjo_prompt_colors=(${(kv)pc})
local p_date p_line p_rc local p_date p_line p_rc
p_date="$pc[date]%D{%Y-%m-%d} $pc[time]%D{%T}$pc[reset]" p_date="$pc[date]%D{%Y-%m-%d} $pc[time]%D{%T}$pc[reset]"
p_line="$pc[line]%y$pc[reset]" p_line="$pc[line]%y$pc[reset]"
PROMPT= PROMPT=
if [ $verbose ]; then if [ $verbose ]; then
PROMPT+="$pc[host]%m$pc[reset] " PROMPT+="$pc[host]%m$pc[reset] "
fi fi
PROMPT+="$pc[path]%(2~.%~.%/)$pc[reset]" PROMPT+="$pc[path]%(2~.%~.%/)$pc[reset]"
PROMPT+="\$(prompt_wunjo_scm_status)" PROMPT+="\$(prompt_wunjo_scm_status)"
PROMPT+="%(?.. $pc[rc]exited %1v$pc[reset])" PROMPT+="%(?.. $pc[rc]exited %1v$pc[reset])"
PROMPT+=" PROMPT+="
" "
PROMPT+="$pc[hist]%h$pc[reset] " PROMPT+="$pc[hist]%h$pc[reset] "
PROMPT+="$pc[shortpath]%1~$pc[reset]" PROMPT+="$pc[shortpath]%1~$pc[reset]"
PROMPT+="\$(prompt_wunjo_scm_branch)" PROMPT+="\$(prompt_wunjo_scm_branch)"
PROMPT+=" $pc[#]%#$pc[reset] " PROMPT+=" $pc[#]%#$pc[reset] "
RPROMPT= RPROMPT=
if [ $verbose ]; then if [ $verbose ]; then
RPROMPT+="$p_date " RPROMPT+="$p_date "
fi fi
RPROMPT+="$pc[user]%n$pc[reset]" RPROMPT+="$pc[user]%n$pc[reset]"
RPROMPT+=" $p_line" RPROMPT+=" $p_line"
export PROMPT RPROMPT export PROMPT RPROMPT
precmd_functions+='prompt_wunjo_precmd' precmd_functions+='prompt_wunjo_precmd'
} }
prompt_wunjo_precmd() { prompt_wunjo_precmd() {
local ex=$? local ex=$?
psvar=() psvar=()
if [[ $ex -ge 128 ]]; then if [[ $ex -ge 128 ]]; then
sig=$signals[$ex-127] sig=$signals[$ex-127]
psvar[1]="sig${(L)sig}" psvar[1]="sig${(L)sig}"
else else
psvar[1]="$ex" psvar[1]="$ex"
fi fi
} }
prompt_wunjo_scm_status() { prompt_wunjo_scm_status() {
zgit_isgit || return zgit_isgit || return
local -A pc local -A pc
pc=(${(kv)wunjo_prompt_colors}) pc=(${(kv)wunjo_prompt_colors})
head=$(zgit_head) head=$(zgit_head)
gitcommit=$(revstring $head) gitcommit=$(revstring $head)
local -a commits local -a commits
if zgit_rebaseinfo; then if zgit_rebaseinfo; then
orig_commit=$(revstring $zgit_info[rb_head]) orig_commit=$(revstring $zgit_info[rb_head])
orig_name=$(git name-rev --name-only $zgit_info[rb_head]) orig_name=$(git name-rev --name-only $zgit_info[rb_head])
orig="$pc[scm_branch]$orig_name$pc[punc]($pc[scm_commitid]$orig_commit$pc[punc])" orig="$pc[scm_branch]$orig_name$pc[punc]($pc[scm_commitid]$orig_commit$pc[punc])"
onto_commit=$(revstring $zgit_info[rb_onto]) onto_commit=$(revstring $zgit_info[rb_onto])
onto_name=$(git name-rev --name-only $zgit_info[rb_onto]) onto_name=$(git name-rev --name-only $zgit_info[rb_onto])
onto="$pc[scm_branch]$onto_name$pc[punc]($pc[scm_commitid]$onto_commit$pc[punc])" onto="$pc[scm_branch]$onto_name$pc[punc]($pc[scm_commitid]$onto_commit$pc[punc])"
if [ -n "$zgit_info[rb_upstream]" ] && [ $zgit_info[rb_upstream] != $zgit_info[rb_onto] ]; then if [ -n "$zgit_info[rb_upstream]" ] && [ $zgit_info[rb_upstream] != $zgit_info[rb_onto] ]; then
upstream_commit=$(revstring $zgit_info[rb_upstream]) upstream_commit=$(revstring $zgit_info[rb_upstream])
upstream_name=$(git name-rev --name-only $zgit_info[rb_upstream]) upstream_name=$(git name-rev --name-only $zgit_info[rb_upstream])
upstream="$pc[scm_branch]$upstream_name$pc[punc]($pc[scm_commitid]$upstream_commit$pc[punc])" upstream="$pc[scm_branch]$upstream_name$pc[punc]($pc[scm_commitid]$upstream_commit$pc[punc])"
commits+="rebasing $upstream$pc[reset]..$orig$pc[reset] onto $onto$pc[reset]" commits+="rebasing $upstream$pc[reset]..$orig$pc[reset] onto $onto$pc[reset]"
else else
commits+="rebasing $onto$pc[reset]..$orig$pc[reset]" commits+="rebasing $onto$pc[reset]..$orig$pc[reset]"
fi fi
local -a revs local -a revs
revs=($(git rev-list $zgit_info[rb_onto]..HEAD)) revs=($(git rev-list $zgit_info[rb_onto]..HEAD))
if [ $#revs -gt 0 ]; then if [ $#revs -gt 0 ]; then
commits+="\n$#revs commits in" commits+="\n$#revs commits in"
fi fi
if [ -f $zgit_info[dotest]/message ]; then if [ -f $zgit_info[dotest]/message ]; then
mess=$(head -n1 $zgit_info[dotest]/message) mess=$(head -n1 $zgit_info[dotest]/message)
commits+="on $mess" commits+="on $mess"
fi fi
elif [ -n "$gitcommit" ]; then elif [ -n "$gitcommit" ]; then
commits+="on $pc[scm_branch]$head$pc[punc]($pc[scm_commitid]$gitcommit$pc[punc])$pc[reset]" commits+="on $pc[scm_branch]$head$pc[punc]($pc[scm_commitid]$gitcommit$pc[punc])$pc[reset]"
local track_merge=$(zgit_tracking_merge) local track_merge=$(zgit_tracking_merge)
if [ -n "$track_merge" ]; then if [ -n "$track_merge" ]; then
if git rev-parse --verify -q $track_merge >/dev/null; then if git rev-parse --verify -q $track_merge >/dev/null; then
local track_remote=$(zgit_tracking_remote) local track_remote=$(zgit_tracking_remote)
local tracked=$(revstring $track_merge 2>/dev/null) local tracked=$(revstring $track_merge 2>/dev/null)
local -a revs local -a revs
revs=($(git rev-list --reverse $track_merge..HEAD)) revs=($(git rev-list --reverse $track_merge..HEAD))
if [ $#revs -gt 0 ]; then if [ $#revs -gt 0 ]; then
local base=$(revstring $revs[1]~1) local base=$(revstring $revs[1]~1)
local base_name=$(git name-rev --name-only $base) local base_name=$(git name-rev --name-only $base)
local base_short=$(revstring $base) local base_short=$(revstring $base)
local word_commits local word_commits
if [ $#revs -gt 1 ]; then if [ $#revs -gt 1 ]; then
word_commits='commits' word_commits='commits'
else else
word_commits='commit' word_commits='commit'
fi fi
local conj="since" local conj="since"
if [[ "$base" == "$tracked" ]]; then if [[ "$base" == "$tracked" ]]; then
conj+=" tracked" conj+=" tracked"
tracked= tracked=
fi fi
commits+="$#revs $word_commits $conj $pc[scm_branch]$base_name$pc[punc]($pc[scm_commitid]$base_short$pc[punc])$pc[reset]" commits+="$#revs $word_commits $conj $pc[scm_branch]$base_name$pc[punc]($pc[scm_commitid]$base_short$pc[punc])$pc[reset]"
fi fi
if [ -n "$tracked" ]; then if [ -n "$tracked" ]; then
local track_name=$track_merge local track_name=$track_merge
if [[ $track_remote == "." ]]; then if [[ $track_remote == "." ]]; then
track_name=${track_name##*/} track_name=${track_name##*/}
fi fi
tracked=$(revstring $tracked) tracked=$(revstring $tracked)
commits+="tracking $pc[scm_branch]$track_name$pc[punc]" commits+="tracking $pc[scm_branch]$track_name$pc[punc]"
if [[ "$tracked" != "$gitcommit" ]]; then if [[ "$tracked" != "$gitcommit" ]]; then
commits[$#commits]+="($pc[scm_commitid]$tracked$pc[punc])" commits[$#commits]+="($pc[scm_commitid]$tracked$pc[punc])"
fi fi
commits[$#commits]+="$pc[reset]" commits[$#commits]+="$pc[reset]"
fi fi
fi fi
fi fi
fi fi
gitsvn=$(git rev-parse --verify -q --short git-svn) gitsvn=$(git rev-parse --verify -q --short git-svn)
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
gitsvnrev=$(zgit_svnhead $gitsvn) gitsvnrev=$(zgit_svnhead $gitsvn)
gitsvn=$(revstring $gitsvn) gitsvn=$(revstring $gitsvn)
if [ -n "$gitsvnrev" ]; then if [ -n "$gitsvnrev" ]; then
local svninfo='' local svninfo=''
local -a revs local -a revs
svninfo+="$pc[default]svn$pc[punc]:$pc[scm_branch]r$gitsvnrev" svninfo+="$pc[default]svn$pc[punc]:$pc[scm_branch]r$gitsvnrev"
revs=($(git rev-list git-svn..HEAD)) revs=($(git rev-list git-svn..HEAD))
if [ $#revs -gt 0 ]; then if [ $#revs -gt 0 ]; then
svninfo+="$pc[punc]@$pc[default]HEAD~$#revs" svninfo+="$pc[punc]@$pc[default]HEAD~$#revs"
svninfo+="$pc[punc]($pc[scm_commitid]$gitsvn$pc[punc])" svninfo+="$pc[punc]($pc[scm_commitid]$gitsvn$pc[punc])"
fi fi
commits+=$svninfo commits+=$svninfo
fi fi
fi fi
if [ $#commits -gt 0 ]; then if [ $#commits -gt 0 ]; then
echo -n " ${(j: :)commits}" echo -n " ${(j: :)commits}"
fi fi
} }
prompt_wunjo_scm_branch() { prompt_wunjo_scm_branch() {
zgit_isgit || return zgit_isgit || return
local -A pc local -A pc
pc=(${(kv)wunjo_prompt_colors}) pc=(${(kv)wunjo_prompt_colors})
echo -n "$pc[punc]:$pc[scm_branch]$(zgit_head)" echo -n "$pc[punc]:$pc[scm_branch]$(zgit_head)"
if zgit_inworktree; then if zgit_inworktree; then
if ! zgit_isindexclean; then if ! zgit_isindexclean; then
echo -n "$pc[scm_status_staged]+" echo -n "$pc[scm_status_staged]+"
fi fi
local -a dirty local -a dirty
if ! zgit_isworktreeclean; then if ! zgit_isworktreeclean; then
dirty+='!' dirty+='!'
fi fi
if zgit_hasunmerged; then if zgit_hasunmerged; then
dirty+='*' dirty+='*'
fi fi
if zgit_hasuntracked; then if zgit_hasuntracked; then
dirty+='?' dirty+='?'
fi fi
if [ $#dirty -gt 0 ]; then if [ $#dirty -gt 0 ]; then
echo -n "$pc[scm_status_dirty]${(j::)dirty}" echo -n "$pc[scm_status_dirty]${(j::)dirty}"
fi fi
fi fi
echo $pc[reset] echo $pc[reset]
} }
prompt_wunjo_setup "$@" prompt_wunjo_setup "$@"

View File

@ -6,245 +6,242 @@ typeset -gA zgit_info
zgit_info=() zgit_info=()
zgit_chpwd_hook() { zgit_chpwd_hook() {
zgit_info_update zgit_info_update
} }
zgit_preexec_hook() { zgit_preexec_hook() {
if [[ $2 == git\ * ]] || [[ $2 == *\ git\ * ]]; then if [[ $2 == git\ * ]] || [[ $2 == *\ git\ * ]]; then
zgit_precmd_do_update=1 zgit_precmd_do_update=1
fi fi
} }
zgit_precmd_hook() { zgit_precmd_hook() {
if [ $zgit_precmd_do_update ]; then if [ $zgit_precmd_do_update ]; then
unset zgit_precmd_do_update unset zgit_precmd_do_update
zgit_info_update zgit_info_update
fi fi
} }
zgit_info_update() { zgit_info_update() {
zgit_info=() zgit_info=()
local gitdir="$(git rev-parse --git-dir 2>/dev/null)" local gitdir="$(git rev-parse --git-dir 2>/dev/null)"
if [ $? -ne 0 ] || [ -z "$gitdir" ]; then if [ $? -ne 0 ] || [ -z "$gitdir" ]; then
return return
fi fi
zgit_info[dir]=$gitdir zgit_info[dir]=$gitdir
zgit_info[bare]=$(git rev-parse --is-bare-repository) zgit_info[bare]=$(git rev-parse --is-bare-repository)
zgit_info[inwork]=$(git rev-parse --is-inside-work-tree) zgit_info[inwork]=$(git rev-parse --is-inside-work-tree)
} }
zgit_isgit() { zgit_isgit() {
if [ -z "$zgit_info[dir]" ]; then if [ -z "$zgit_info[dir]" ]; then
return 1 return 1
else else
return 0 return 0
fi fi
} }
zgit_inworktree() { zgit_inworktree() {
zgit_isgit || return zgit_isgit || return
if [ "$zgit_info[inwork]" = "true" ]; then if [ "$zgit_info[inwork]" = "true" ]; then
return 0 return 0
else else
return 1 return 1
fi fi
} }
zgit_isbare() { zgit_isbare() {
zgit_isgit || return zgit_isgit || return
if [ "$zgit_info[bare]" = "true" ]; then if [ "$zgit_info[bare]" = "true" ]; then
return 0 return 0
else else
return 1 return 1
fi fi
} }
zgit_head() { zgit_head() {
zgit_isgit || return 1 zgit_isgit || return 1
if [ -z "$zgit_info[head]" ]; then if [ -z "$zgit_info[head]" ]; then
local name='' local name=''
name=$(git symbolic-ref -q HEAD) name=$(git symbolic-ref -q HEAD)
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
if [[ $name == refs/(heads|tags)/* ]]; then if [[ $name == refs/(heads|tags)/* ]]; then
name=${name#refs/(heads|tags)/} name=${name#refs/(heads|tags)/}
fi fi
else else
name=$(git name-rev --name-only --no-undefined --always HEAD) name=$(git name-rev --name-only --no-undefined --always HEAD)
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
return 1 return 1
elif [[ $name == remotes/* ]]; then elif [[ $name == remotes/* ]]; then
name=${name#remotes/} name=${name#remotes/}
fi fi
fi fi
zgit_info[head]=$name zgit_info[head]=$name
fi fi
echo $zgit_info[head] echo $zgit_info[head]
} }
zgit_branch() { zgit_branch() {
zgit_isgit || return 1 zgit_isgit || return 1
zgit_isbare && return 1 zgit_isbare && return 1
if [ -z "$zgit_info[branch]" ]; then if [ -z "$zgit_info[branch]" ]; then
local branch=$(git symbolic-ref HEAD 2>/dev/null) local branch=$(git symbolic-ref HEAD 2>/dev/null)
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
branch=${branch##*/} branch=${branch##*/}
else else
branch=$(git name-rev --name-only --always HEAD) branch=$(git name-rev --name-only --always HEAD)
fi fi
zgit_info[branch]=$branch zgit_info[branch]=$branch
fi fi
echo $zgit_info[branch] echo $zgit_info[branch]
return 0 return 0
} }
zgit_tracking_remote() { zgit_tracking_remote() {
zgit_isgit || return 1 zgit_isgit || return 1
zgit_isbare && return 1 zgit_isbare && return 1
local branch local branch
if [ -n "$1" ]; then if [ -n "$1" ]; then
branch=$1 branch=$1
elif [ -z "$zgit_info[branch]" ]; then elif [ -z "$zgit_info[branch]" ]; then
branch=$(zgit_branch) branch=$(zgit_branch)
[ $? -ne 0 ] && return 1 [ $? -ne 0 ] && return 1
else else
branch=$zgit_info[branch] branch=$zgit_info[branch]
fi fi
local k="tracking_$branch" local k="tracking_$branch"
local remote local remote
if [ -z "$zgit_info[$k]" ]; then if [ -z "$zgit_info[$k]" ]; then
remote=$(git config branch.$branch.remote) remote=$(git config branch.$branch.remote)
zgit_info[$k]=$remote zgit_info[$k]=$remote
fi fi
echo $zgit_info[$k] echo $zgit_info[$k]
return 0 return 0
} }
zgit_tracking_merge() { zgit_tracking_merge() {
zgit_isgit || return 1 zgit_isgit || return 1
zgit_isbare && return 1 zgit_isbare && return 1
local branch local branch
if [ -z "$zgit_info[branch]" ]; then if [ -z "$zgit_info[branch]" ]; then
branch=$(zgit_branch) branch=$(zgit_branch)
[ $? -ne 0 ] && return 1 [ $? -ne 0 ] && return 1
else else
branch=$zgit_info[branch] branch=$zgit_info[branch]
fi fi
local remote=$(zgit_tracking_remote $branch) local remote=$(zgit_tracking_remote $branch)
[ $? -ne 0 ] && return 1 [ $? -ne 0 ] && return 1
if [ -n "$remote" ]; then # tracking branch if [ -n "$remote" ]; then # tracking branch
local merge=$(git config branch.$branch.merge) local merge=$(git config branch.$branch.merge)
if [ $remote != "." ]; then if [ $remote != "." ]; then
merge=$remote/$(basename $merge) merge=$remote/$(basename $merge)
fi fi
echo $merge echo $merge
return 0 return 0
else else
return 1 return 1
fi fi
} }
zgit_isindexclean() { zgit_isindexclean() {
zgit_isgit || return 1 zgit_isgit || return 1
if git diff --quiet --cached 2>/dev/null; then if git diff --quiet --cached 2>/dev/null; then
return 0 return 0
else else
return 1 return 1
fi fi
} }
zgit_isworktreeclean() { zgit_isworktreeclean() {
zgit_isgit || return 1 zgit_isgit || return 1
if git diff --quiet 2>/dev/null; then if git diff --quiet 2>/dev/null; then
return 0 return 0
else else
return 1 return 1
fi fi
} }
zgit_hasuntracked() { zgit_hasuntracked() {
zgit_isgit || return 1 zgit_isgit || return 1
local -a flist local -a flist
flist=($(git ls-files --others --exclude-standard)) flist=($(git ls-files --others --exclude-standard))
if [ $#flist -gt 0 ]; then if [ $#flist -gt 0 ]; then
return 0 return 0
else else
return 1 return 1
fi fi
} }
zgit_hasunmerged() { zgit_hasunmerged() {
zgit_isgit || return 1 zgit_isgit || return 1
local -a flist local -a flist
flist=($(git ls-files -u)) flist=($(git ls-files -u))
if [ $#flist -gt 0 ]; then if [ $#flist -gt 0 ]; then
return 0 return 0
else else
return 1 return 1
fi fi
} }
zgit_svnhead() { zgit_svnhead() {
zgit_isgit || return 1 zgit_isgit || return 1
local commit=$1 local commit=$1
if [ -z "$commit" ]; then if [ -z "$commit" ]; then
commit='HEAD' commit='HEAD'
fi fi
git show --raw $commit | \ git show --raw $commit | \
grep git-svn-id | \ grep git-svn-id | \
sed -re 's/^\s*git-svn-id: .*@([0-9]+).*$/\1/' sed -re 's/^\s*git-svn-id: .*@([0-9]+).*$/\1/'
} }
zgit_rebaseinfo() { zgit_rebaseinfo() {
zgit_isgit || return 1 zgit_isgit || return 1
if [ -d $zgit_info[dir]/rebase-merge ]; then if [ -d $zgit_info[dir]/rebase-merge ]; then
dotest=$zgit_info[dir]/rebase-merge dotest=$zgit_info[dir]/rebase-merge
elif [ -d $zgit_info[dir]/.dotest-merge ]; then elif [ -d $zgit_info[dir]/.dotest-merge ]; then
dotest=$zgit_info[dir]/.dotest-merge dotest=$zgit_info[dir]/.dotest-merge
elif [ -d .dotest ]; then elif [ -d .dotest ]; then
dotest=.dotest dotest=.dotest
else else
return 1 return 1
fi fi
zgit_info[dotest]=$dotest zgit_info[dotest]=$dotest
zgit_info[rb_onto]=$(cat "$dotest/onto") zgit_info[rb_onto]=$(cat "$dotest/onto")
zgit_info[rb_upstream]=$(cat "$dotest/upstream") zgit_info[rb_upstream]=$(cat "$dotest/upstream")
if [ -f "$dotest/orig-head" ]; then if [ -f "$dotest/orig-head" ]; then
zgit_info[rb_head]=$(cat "$dotest/orig-head") zgit_info[rb_head]=$(cat "$dotest/orig-head")
elif [ -f "$dotest/head" ]; then elif [ -f "$dotest/head" ]; then
zgit_info[rb_head]=$(cat "$dotest/head") zgit_info[rb_head]=$(cat "$dotest/head")
fi fi
zgit_info[rb_head_name]=$(cat "$dotest/head-name") zgit_info[rb_head_name]=$(cat "$dotest/head-name")
return 0 return 0
} }
zgitinit() { zgitinit() {
typeset -ga chpwd_functions typeset -ga chpwd_functions
typeset -ga preexec_functions typeset -ga preexec_functions
typeset -ga precmd_functions typeset -ga precmd_functions
chpwd_functions+='zgit_chpwd_hook' chpwd_functions+='zgit_chpwd_hook'
preexec_functions+='zgit_preexec_hook' preexec_functions+='zgit_preexec_hook'
precmd_functions+='zgit_precmd_hook' precmd_functions+='zgit_precmd_hook'
} }
zgitinit zgitinit
# Temporarily disabling as this is slowing down new term tabs, especially when opening a # Show git info when shell opens
# work git directory zgit_info_update
# zgit_info_update
# vim:set ft=zsh: