Created
March 2, 2011 14:24
-
-
Save hchbaw/851005 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# zaw.zsh source for 'git show-branch'. | |
# Thank you very much, nakamuray! | |
# https://github.com/nakamuray/zaw | |
zaw-src-git-showbranch () { | |
git rev-parse -q --is-inside-work-tree >/dev/null || return 1 | |
#local b="${orig_lbuffer}${orig_rbuffer}" | |
local b="$BUFFER" | |
local z="$(git rev-parse --git-dir)""/zaw-src-git-showbranch" | |
{ | |
zaw-src-git-showbranch~ "$b" "$z" >| ${z}.tmp || return 1 | |
} always { | |
mv -f ${z}.tmp ${z} | |
} | |
: ${(A)candidates::=${(@f)"$(<"${z}")"}} | |
[[ -n "$b" ]] || { | |
BUFFER=$candidates[1] | |
(( $+functions[_zsh_highlight] )) && _zsh_highlight | |
} | |
shift candidates | |
actions=(zaw-callback-git-showbranch) | |
act_descriptions=("setup edit buffer") | |
options+=(-m) | |
} | |
zaw-src-git-showbranch~ () { | |
local gb="$1" | |
local zf="$2" | |
setopt localoptions extendedglob | |
case "$gb" in | |
([[:space:]]#'git show-branch '*) | |
echo "$gb"; "${(z)gb}"; return $? | |
;; | |
([[:space:]]##) | |
echo " "; git show-branch; return $? | |
;; | |
esac | |
[[ -s "$zf" ]] && { "$0" "$(head -n1 $zf)" "$zf"; return $? } | |
return -1 | |
} | |
zaw-callback-git-showbranch () { | |
setopt localoptions extendedglob | |
local -a commitish | |
local line=; for line in ${@[@]}; do | |
zaw-callback-git-showbranch-accum "$line" "" commitish | |
done | |
zaw-callback-git-showbranch~ "${commitish[@]}" | |
} | |
zaw-callback-git-showbranch-accum () { | |
local b="$1" | |
local a="$2" | |
local p="$3" | |
local -a match mbegin mend | |
[[ "$b" == (#b)(*)\[(*)\]* ]] && | |
{ "$0" "$match[1]" "$match[2]" "$p" ; return $? } | |
[[ -n "$a" ]] && { | |
local -a tmp; : ${(A)tmp::=${(PA)p}} | |
tmp+="$a"; : ${(PA)p::=${(A)tmp}}; return $? | |
} | |
return -1 | |
} | |
zaw-callback-git-showbranch~ () { | |
BUFFER="noglob zargs -- $@ -- git" | |
((CURSOR=$#BUFFER)) | |
} | |
zaw-register-src -n git-showbranch zaw-src-git-showbranch | |
#print -z 'git show-branch master next pu' | |
#zaw-src-git-showbranch~ "" .git/zaw-src-git-showbranch ; echo $? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

Hello, git show-branch!