From 2b1c01d22ef280ef3a6efd70db2b9aa58359ee36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Sun, 27 May 2018 10:38:26 +0200 Subject: parse-options: option to let --git-completion-helper show negative form MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When 7fb6aefd2a (Merge branch 'nd/parseopt-completion' - 2018-03-14) is merged, the completion for negative form is left out because the series is alread long and it could be done in a follow up series. This is it. --git-completion-helper now provides --no-xxx so that git-completion.bash can drop the extra custom --no-xxx in the script. It adds a lot more --no-xxx than what's current provided by the git-completion.bash script. We'll trim that down later. Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- contrib/completion/git-completion.bash | 38 +++++++++++++--------------------- 1 file changed, 14 insertions(+), 24 deletions(-) (limited to 'contrib/completion') diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 961a0ed76f..952e660f06 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -1126,7 +1126,7 @@ _git_am () return ;; --*) - __gitcomp_builtin am "--no-utf8" \ + __gitcomp_builtin am "" \ "$__git_am_inprogress_options" return esac @@ -1226,9 +1226,7 @@ _git_branch () __git_complete_refs --cur="${cur##--set-upstream-to=}" ;; --*) - __gitcomp_builtin branch "--no-color --no-abbrev - --no-track --no-column - " + __gitcomp_builtin branch ;; *) if [ $only_local_ref = "y" -a $has_r = "n" ]; then @@ -1269,7 +1267,7 @@ _git_checkout () __gitcomp "diff3 merge" "" "${cur##--conflict=}" ;; --*) - __gitcomp_builtin checkout "--no-track --no-recurse-submodules" + __gitcomp_builtin checkout ;; *) # check if --track, --no-track, or --no-guess was specified @@ -1332,7 +1330,7 @@ _git_clone () { case "$cur" in --*) - __gitcomp_builtin clone "--no-single-branch" + __gitcomp_builtin clone return ;; esac @@ -1365,7 +1363,7 @@ _git_commit () return ;; --*) - __gitcomp_builtin commit "--no-edit --verify" + __gitcomp_builtin commit return esac @@ -1468,7 +1466,7 @@ _git_fetch () return ;; --*) - __gitcomp_builtin fetch "--no-tags" + __gitcomp_builtin fetch return ;; esac @@ -1505,7 +1503,7 @@ _git_fsck () { case "$cur" in --*) - __gitcomp_builtin fsck "--no-reflogs" + __gitcomp_builtin fsck return ;; esac @@ -1612,7 +1610,7 @@ _git_ls_files () { case "$cur" in --*) - __gitcomp_builtin ls-files "--no-empty-directory" + __gitcomp_builtin ls-files return ;; esac @@ -1763,12 +1761,7 @@ _git_merge () case "$cur" in --*) - __gitcomp_builtin merge "--no-rerere-autoupdate - --no-commit --no-edit --no-ff - --no-log --no-progress - --no-squash --no-stat - --no-verify-signatures - " + __gitcomp_builtin merge return esac __git_complete_refs @@ -1867,10 +1860,7 @@ _git_pull () return ;; --*) - __gitcomp_builtin pull "--no-autostash --no-commit --no-edit - --no-ff --no-log --no-progress --no-rebase - --no-squash --no-stat --no-tags - --no-verify-signatures" + __gitcomp_builtin pull return ;; @@ -2061,7 +2051,7 @@ _git_status () return ;; --*) - __gitcomp_builtin status "--no-column" + __gitcomp_builtin status return ;; esac @@ -2615,7 +2605,7 @@ _git_remote () case "$subcommand,$cur" in add,--*) - __gitcomp_builtin remote_add "--no-tags" + __gitcomp_builtin remote_add ;; add,*) ;; @@ -2695,7 +2685,7 @@ _git_revert () fi case "$cur" in --*) - __gitcomp_builtin revert "--no-edit" \ + __gitcomp_builtin revert "" \ "$__git_revert_inprogress_options" return ;; @@ -2765,7 +2755,7 @@ _git_show_branch () { case "$cur" in --*) - __gitcomp_builtin show-branch "--no-color" + __gitcomp_builtin show-branch return ;; esac -- cgit v1.2.3 From b221b5ab9b92f3def37184db6e052ec87d7635b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Wed, 6 Jun 2018 11:41:39 +0200 Subject: completion: collapse extra --no-.. options MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The commands that make use of --git-completion-helper feature could now produce a lot of --no-xxx options that a command can take. This in many case could nearly double the amount of completable options, using more screen estate and also harder to search for the wanted option. This patch attempts to mitigate that by collapsing extra --no- options, the ones that are added by --git-completion-helper and not in original struct option arrays. The "--no-..." option will be displayed in this case to hint about more options, e.g. > ~/w/git $ git clone -- --bare --origin= --branch= --progress --checkout --quiet --config= --recurse-submodules --depth= --reference= --dissociate --reference-if-able= --filter= --separate-git-dir= --hardlinks --shallow-exclude= --ipv4 --shallow-since= --ipv6 --shallow-submodules --jobs= --shared --local --single-branch --mirror --tags --no-... --template= --no-checkout --upload-pack= --no-hardlinks --verbose --no-tags and when you complete it with --no-, all negative options will be presented: > ~/w/git $ git clone --no- --no-bare --no-quiet --no-branch --no-recurse-submodules --no-checkout --no-reference --no-config --no-reference-if-able --no-depth --no-separate-git-dir --no-dissociate --no-shallow-exclude --no-filter --no-shallow-since --no-hardlinks --no-shallow-submodules --no-ipv4 --no-shared --no-ipv6 --no-single-branch --no-jobs --no-tags --no-local --no-template --no-mirror --no-upload-pack --no-origin --no-verbose --no-progress Corner case: to make sure that people will never accidentally complete the fake option "--no-..." there must be one real --no- in the first complete listing even if it's not from the original struct option. PS. This could could be made simpler with ";&" to fall through from "--no-*" block and share the code but ";&" is not available on bash-3 (i.e. Mac) Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- contrib/completion/git-completion.bash | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'contrib/completion') diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 952e660f06..425d06256f 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -266,9 +266,32 @@ __gitcomp () case "$cur_" in --*=) ;; + --no-*) + local c i=0 IFS=$' \t\n' + for c in $1; do + if [[ $c == "--" ]]; then + continue + fi + c="$c${4-}" + if [[ $c == "$cur_"* ]]; then + case $c in + --*=*|*.) ;; + *) c="$c " ;; + esac + COMPREPLY[i++]="${2-}$c" + fi + done + ;; *) local c i=0 IFS=$' \t\n' for c in $1; do + if [[ $c == "--" ]]; then + c="--no-...${4-}" + if [[ $c == "$cur_"* ]]; then + COMPREPLY[i++]="${2-}$c " + fi + break + fi c="$c${4-}" if [[ $c == "$cur_"* ]]; then case $c in -- cgit v1.2.3