Skip to content

Commit 3ac62c0

Browse files
committed
Zsh completion for stg rebase new-base-id
The zsh completion for `stg rebase` now offers completions for local and remote heads for the new-base-id. Fixes #102 Signed-off-by: Peter Grayson <[email protected]>
1 parent d6c35e7 commit 3ac62c0

File tree

1 file changed

+60
-7
lines changed

1 file changed

+60
-7
lines changed

completion/stgit.zsh

Lines changed: 60 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ _stg-rebase() {
390390
__stg_add_args_merged
391391
subcmd_args+=(
392392
'(-n --nopush)'{-n,--nopush}'[do not push patches after rebasing]'
393-
':new-base-id:'
393+
':new-base-id:__stg_heads'
394394
)
395395
_arguments -s -S $subcmd_args
396396
}
@@ -645,13 +645,66 @@ __stg_add_args_sign() {
645645
)
646646
}
647647

648-
__stg_branch_all() {
649-
declare -a all_branches
650-
all_branches=(
651-
${${(f)"$(_call_program remote-branch-refs git for-each-ref --format='"%(refname)"' refs/heads 2>/dev/null)"}#refs/heads/}
652-
)
648+
__stg_heads () {
649+
_alternative 'heads-local::__stg_heads_local' 'heads-remote::__stg_heads_remote'
650+
}
651+
652+
__stg_heads_local () {
653+
local f gitdir
654+
declare -a heads
655+
656+
heads=(${(f)"$(_call_program headrefs git for-each-ref --format='"%(refname:short)"' refs/heads 2>/dev/null)"})
657+
gitdir=$(_call_program gitdir git rev-parse --git-dir 2>/dev/null)
658+
if __stg_git_command_successful $pipestatus; then
659+
for f in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD; do
660+
[[ -f $gitdir/$f ]] && heads+=$f
661+
done
662+
[[ -f $gitdir/refs/stash ]] && heads+=stash
663+
[[ -f $gitdir/refs/bisect/bad ]] && heads+=bisect/bad
664+
fi
665+
666+
__stg_git_describe_commit heads heads-local "local head" "$@"
667+
}
668+
669+
__stg_heads_remote () {
670+
declare -a heads
671+
672+
heads=(${(f)"$(_call_program headrefs git for-each-ref --format='"%(refname:short)"' refs/remotes 2>/dev/null)"})
673+
674+
__stg_git_describe_commit heads heads-remote "remote head" "$@"
675+
}
676+
677+
__stg_git_command_successful () {
678+
if (( ${#*:#0} > 0 )); then
679+
_message 'not a git repository'
680+
return 1
681+
fi
682+
return 0
683+
}
684+
685+
__stg_git_describe_commit () {
686+
__stg_git_describe_branch $1 $2 $3 -M 'r:|/=* r:|=*' "${(@)argv[4,-1]}"
687+
}
688+
689+
__stg_git_describe_branch () {
690+
local __commits_in=$1
691+
local __tag=$2
692+
local __desc=$3
693+
shift 3
694+
695+
integer maxverbose
696+
if zstyle -s :completion:$curcontext: max-verbose maxverbose &&
697+
(( ${compstate[nmatches]} <= maxverbose )); then
698+
local __c
699+
local -a __commits
700+
for __c in ${(P)__commits_in}; do
701+
__commits+=("${__c}:${$(_call_program describe git rev-list -1 --oneline $__c)//:/\\:}")
702+
done
703+
_describe -t $__tag $__desc __commits "$@"
704+
else
653705
local expl
654-
_wanted -V branches expl "branch" compadd $all_branches
706+
_wanted $__tag expl $__desc compadd "$@" -a - $__commits_in
707+
fi
655708
}
656709

657710
__stg_branch_stgit() {

0 commit comments

Comments
 (0)