summaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2021-05-07 12:47:41 +0900
committerLibravatar Junio C Hamano <gitster@pobox.com>2021-05-07 12:47:41 +0900
commit18e1ba10927b15f66a32c86f61133e9adf79f9cf (patch)
tree47a2d92a731857e406ce2c5e7e62ed0a97173f94 /contrib
parentMerge branch 'dl/complete-stash' (diff)
parentgit-completion.bash: consolidate cases in _git_stash() (diff)
downloadtgif-18e1ba10927b15f66a32c86f61133e9adf79f9cf.tar.xz
Merge branch 'dl/complete-stash-updates'
Further update the command line completion (in contrib/) for "git stash". * dl/complete-stash-updates: git-completion.bash: consolidate cases in _git_stash() git-completion.bash: use $__git_cmd_idx in more places git-completion.bash: rename to $__git_cmd_idx git-completion.bash: separate some commands onto their own line
Diffstat (limited to 'contrib')
-rw-r--r--contrib/completion/git-completion.bash98
1 files changed, 51 insertions, 47 deletions
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 016f90bc21..b09cb62c9f 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1006,8 +1006,8 @@ __git_complete_revlist ()
__git_complete_remote_or_refspec ()
{
- local cur_="$cur" cmd="${words[1]}"
- local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
+ local cur_="$cur" cmd="${words[__git_cmd_idx]}"
+ local i c=$((__git_cmd_idx+1)) remote="" pfx="" lhs=1 no_complete_refspec=0
if [ "$cmd" = "remote" ]; then
((c++))
fi
@@ -1176,7 +1176,7 @@ __git_aliased_command ()
# --show-idx: Optionally show the index of the found word in the $words array.
__git_find_on_cmdline ()
{
- local word c=1 show_idx
+ local word c="$__git_cmd_idx" show_idx
while test $# -gt 1; do
case "$1" in
@@ -1221,7 +1221,7 @@ __git_find_last_on_cmdline ()
done
local wordlist="$1"
- while [ $c -gt 1 ]; do
+ while [ $c -gt "$__git_cmd_idx" ]; do
((c--))
for word in $wordlist; do
if [ "$word" = "${words[c]}" ]; then
@@ -1306,7 +1306,7 @@ __git_count_arguments ()
local word i c=0
# Skip "git" (first argument)
- for ((i=1; i < ${#words[@]}; i++)); do
+ for ((i="$__git_cmd_idx"; i < ${#words[@]}; i++)); do
word="${words[i]}"
case "$word" in
@@ -1442,7 +1442,7 @@ __git_ref_fieldlist="refname objecttype objectsize objectname upstream push HEAD
_git_branch ()
{
- local i c=1 only_local_ref="n" has_r="n"
+ local i c="$__git_cmd_idx" only_local_ref="n" has_r="n"
while [ $c -lt $cword ]; do
i="${words[c]}"
@@ -1474,12 +1474,12 @@ _git_branch ()
_git_bundle ()
{
- local cmd="${words[__git_subcommand_idx+1]}"
+ local cmd="${words[__git_cmd_idx+1]}"
case "$cword" in
- $((__git_subcommand_idx+1)))
+ $((__git_cmd_idx+1)))
__gitcomp "create list-heads verify unbundle"
;;
- $((__git_subcommand_idx+2)))
+ $((__git_cmd_idx+2)))
# looking for a file
;;
*)
@@ -1894,7 +1894,7 @@ _git_grep ()
esac
case "$cword,$prev" in
- $((__git_subcommand_idx+1)),*|*,-*)
+ $((__git_cmd_idx+1)),*|*,-*)
__git_complete_symbol && return
;;
esac
@@ -2474,7 +2474,7 @@ _git_switch ()
__git_config_get_set_variables ()
{
local prevword word config_file= c=$cword
- while [ $c -gt 1 ]; do
+ while [ $c -gt "$__git_cmd_idx" ]; do
word="${words[c]}"
case "$word" in
--system|--global|--local|--file=*)
@@ -3017,7 +3017,7 @@ _git_stash ()
local subcommand="$(__git_find_on_cmdline "$subcommands save")"
if [ -z "$subcommand" ]; then
- case "$((cword - __git_subcommand_idx)),$cur" in
+ case "$((cword - __git_cmd_idx)),$cur" in
*,--*)
__gitcomp_builtin stash_push
;;
@@ -3032,21 +3032,6 @@ _git_stash ()
fi
case "$subcommand,$cur" in
- push,--*)
- __gitcomp_builtin stash_push
- ;;
- save,--*)
- __gitcomp_builtin stash_save
- ;;
- pop,--*)
- __gitcomp_builtin stash_pop
- ;;
- apply,--*)
- __gitcomp_builtin stash_apply
- ;;
- drop,--*)
- __gitcomp_builtin stash_drop
- ;;
list,--*)
# NEEDSWORK: can we somehow unify this with the options in _git_log() and _git_show()
__gitcomp_builtin stash_list "$__git_log_common_options $__git_diff_common_options"
@@ -3054,11 +3039,11 @@ _git_stash ()
show,--*)
__gitcomp_builtin stash_show "$__git_diff_common_options"
;;
- branch,--*)
- __gitcomp_builtin stash_branch
+ *,--*)
+ __gitcomp_builtin "stash_$subcommand"
;;
branch,*)
- if [ $cword -eq $((__git_subcommand_idx+2)) ]; then
+ if [ $cword -eq $((__git_cmd_idx+2)) ]; then
__git_complete_refs
else
__gitcomp_nl "$(__git stash list \
@@ -3069,8 +3054,6 @@ _git_stash ()
__gitcomp_nl "$(__git stash list \
| sed -n -e 's/:.*//p')"
;;
- *)
- ;;
esac
}
@@ -3224,7 +3207,7 @@ _git_svn ()
_git_tag ()
{
- local i c=1 f=0
+ local i c="$__git_cmd_idx" f=0
while [ $c -lt $cword ]; do
i="${words[c]}"
case "$i" in
@@ -3276,9 +3259,11 @@ __git_complete_worktree_paths ()
_git_worktree ()
{
local subcommands="add list lock move prune remove unlock"
- local subcommand
+ local subcommand subcommand_idx
- subcommand="$(__git_find_on_cmdline "$subcommands")"
+ subcommand="$(__git_find_on_cmdline --show-idx "$subcommands")"
+ subcommand_idx="${subcommand% *}"
+ subcommand="${subcommand#* }"
case "$subcommand,$cur" in
,*)
@@ -3303,7 +3288,7 @@ _git_worktree ()
# be either the 'add' subcommand, the unstuck
# argument of an option (e.g. branch for -b|-B), or
# the path for the new worktree.
- if [ $cword -eq $((__git_subcommand_idx+2)) ]; then
+ if [ $cword -eq $((subcommand_idx+1)) ]; then
# Right after the 'add' subcommand: have to
# complete the path, so fall back to Bash
# filename completion.
@@ -3327,7 +3312,7 @@ _git_worktree ()
__git_complete_worktree_paths
;;
move,*)
- if [ $cword -eq $((__git_subcommand_idx+2)) ]; then
+ if [ $cword -eq $((subcommand_idx+1)) ]; then
# The first parameter must be an existing working
# tree to be moved.
__git_complete_worktree_paths
@@ -3395,22 +3380,40 @@ __git_main ()
{
local i c=1 command __git_dir __git_repo_path
local __git_C_args C_args_count=0
- local __git_subcommand_idx
+ local __git_cmd_idx
while [ $c -lt $cword ]; do
i="${words[c]}"
case "$i" in
- --git-dir=*) __git_dir="${i#--git-dir=}" ;;
- --git-dir) ((c++)) ; __git_dir="${words[c]}" ;;
- --bare) __git_dir="." ;;
- --help) command="help"; break ;;
- -c|--work-tree|--namespace) ((c++)) ;;
- -C) __git_C_args[C_args_count++]=-C
+ --git-dir=*)
+ __git_dir="${i#--git-dir=}"
+ ;;
+ --git-dir)
+ ((c++))
+ __git_dir="${words[c]}"
+ ;;
+ --bare)
+ __git_dir="."
+ ;;
+ --help)
+ command="help"
+ break
+ ;;
+ -c|--work-tree|--namespace)
+ ((c++))
+ ;;
+ -C)
+ __git_C_args[C_args_count++]=-C
((c++))
__git_C_args[C_args_count++]="${words[c]}"
;;
- -*) ;;
- *) command="$i"; __git_subcommand_idx="$c"; break ;;
+ -*)
+ ;;
+ *)
+ command="$i"
+ __git_cmd_idx="$c"
+ break
+ ;;
esac
((c++))
done
@@ -3432,7 +3435,8 @@ __git_main ()
;;
esac
case "$cur" in
- --*) __gitcomp "
+ --*)
+ __gitcomp "
--paginate
--no-pager
--git-dir=