Skip to content

Instantly share code, notes, and snippets.

@Yasushi
Created September 1, 2008 07:16
Show Gist options
  • Save Yasushi/8281 to your computer and use it in GitHub Desktop.
Save Yasushi/8281 to your computer and use it in GitHub Desktop.
StGIT completion function
#compdef stg
__stg_command_successful () {
if (( ${#pipestatus:#0} > 0 )); then
_message 'not a stg branch or git repository'
return 1
fi
return 0
}
__stg_patch_names () {
local expl
declare -a patch_names
patch_names=(${${(f)"$(_call_program patch-names stg series 2>/dev/null)"}#[+-> ] })
__stg_command_successful || return
_wanted patch-names expl patch-name compadd $* - $patch_names
}
__stg_applied_patch_names () {
local expl
declare -a patch_names
patch_names=(${(f)"$(_call_program applied-patch-names stg applied 2>/dev/null)"})
__stg_command_successful || return
_wanted applied-patch-names expl applied-patch-name compadd $* - $patch_names
}
__stg_unapplied_patch_names () {
local expl
declare -a patch_names
patch_names=(${(f)"$(_call_program unapplied-patch-names stg unapplied 2>/dev/null)"})
__stg_command_successful || return
_wanted unapplied-patch-names expl unapplied-patch-name compadd $* - $patch_names
}
_stg-files () {
_arguments \
{-s,--stat}'[show the diff stat]' \
{-b+,--branch=}'[use BRANCH instead of the default one]' \
{-O+,--diff-opts=}'[options to pass to git-diff]' \
'--bare[bare file names (useful for scripting)]' \
'*:patch-name:__stg_patch_names' && return 0
}
_stg-push () {
_arguments \
{-a,--all}'[push all the unapplied patches]' \
{-n+,--number=}'[push the specified number of patches]' \
'--reverse[push the patches in reverse order]' \
{-m,--merged}'[check for patches merged upstream]' \
'--undo[undo the last patch pushing]' \
'*:unapplied-patch-name:__stg_unapplied_patch_names' && return 0
}
_stg-pop () {
_arguments \
{-a,--all}'[push all the unapplied patches]' \
{-n+,--number=}'[push the specified number of patches]' \
{-k,--keep}'[keep the local changes]' \
'*:applied-patch-name:__stg_applied_patch_names' && return 0
}
_stg(){
if ((CURRENT > 2)); then
local curcontext=$curcontext ret=1
curcontext="${curcontext%:*:*}:stg-$words[2]"
_call_function ret _stg-$words[2]
else
local line
local -a cmd
_call_program help-command stg help \
| sed -n 's/^ \([^ ]*\).*$/\1/p' \
| while read -A line; do
cmd=($line $cmd)
done
_describe -t stg-command 'stg command' cmd
fi
}
_stg "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment