{"thread":{"id":"6666","subject":"[PATCH 7/8] bash: Support unique completion when possible.","startedAt":"2007-02-04T07:38:43Z","lastAt":"2007-02-04T07:38:43Z","messageCount":1,"participants":["Shawn O. Pearce"],"isPatch":true,"patchVersion":1,"patchTotal":8},"messages":[{"id":"33542","messageId":"20070204073843.GG17603@spearce.org","threadId":"6666","inReplyTo":null,"subject":"[PATCH 7/8] bash: Support unique completion when possible.","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2007-02-04T07:38:43Z","receivedAt":"2007-02-04T07:38:43Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Because our use of -o nospace prevents bash from adding a trailing space\nwhen a completion is unique and has been fully completed, we need to\nperform this addition on our own.  This (large) change converts all\nexisting uses of compgen to our wrapper __gitcomp which attempts to\nhandle this by tacking a trailing space onto the end of each offered\noption.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n contrib/completion/git-completion.bash |  190 +++++++++++++++-----------------\n 1 files changed, 91 insertions(+), 99 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 38d6121..3b1f100 100755\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -65,7 +65,7 @@ __gitcomp ()\n {\n \tlocal all c s=$'\\n' IFS=' '$'\\t'$'\\n'\n \tlocal cur=\"${COMP_WORDS[COMP_CWORD]}\"\n-\tif [ -n \"$2\" ]; then\n+\tif [ $# -gt 2 ]; then\n \t\tcur=\"$3\"\n \tfi\n \tfor c in $1; do\n@@ -219,7 +219,7 @@ __git_complete_file ()\n \t\t\t-- \"$cur\"))\n \t\t;;\n \t*)\n-\t\tCOMPREPLY=($(compgen -W \"$(__git_refs)\" -- \"$cur\"))\n+\t\t__gitcomp \"$(__git_refs)\"\n \t\t;;\n \tesac\n }\n@@ -231,15 +231,18 @@ __git_complete_revlist ()\n \t*...*)\n \t\tpfx=\"${cur%...*}...\"\n \t\tcur=\"${cur#*...}\"\n-\t\tCOMPREPLY=($(compgen -P \"$pfx\" -W \"$(__git_refs)\" -- \"$cur\"))\n+\t\t__gitcomp \"$(__git_refs)\" \"$pfx\" \"$cur\"\n \t\t;;\n \t*..*)\n \t\tpfx=\"${cur%..*}..\"\n \t\tcur=\"${cur#*..}\"\n-\t\tCOMPREPLY=($(compgen -P \"$pfx\" -W \"$(__git_refs)\" -- \"$cur\"))\n+\t\t__gitcomp \"$(__git_refs)\" \"$pfx\" \"$cur\"\n+\t\t;;\n+\t*.)\n+\t\t__gitcomp \"$cur.\"\n \t\t;;\n \t*)\n-\t\tCOMPREPLY=($(compgen -W \"$(__git_refs)\" -- \"$cur\"))\n+\t\t__gitcomp \"$(__git_refs)\"\n \t\t;;\n \tesac\n }\n@@ -353,22 +356,19 @@ _git_am ()\n {\n \tlocal cur=\"${COMP_WORDS[COMP_CWORD]}\"\n \tif [ -d .dotest ]; then\n-\t\tCOMPREPLY=($(compgen -W \"\n-\t\t\t--skip --resolved\n-\t\t\t\" -- \"$cur\"))\n+\t\t__gitcomp \"--skip --resolved\"\n \t\treturn\n \tfi\n \tcase \"$cur\" in\n \t--whitespace=*)\n-\t\tCOMPREPLY=($(compgen -W \"$__git_whitespacelist\" \\\n-\t\t\t-- \"${cur##--whitespace=}\"))\n+\t\t__gitcomp \"$__git_whitespacelist\" \"\" \"${cur##--whitespace=}\"\n \t\treturn\n \t\t;;\n \t--*)\n-\t\tCOMPREPLY=($(compgen -W \"\n+\t\t__gitcomp \"\n \t\t\t--signoff --utf8 --binary --3way --interactive\n \t\t\t--whitespace=\n-\t\t\t\" -- \"$cur\"))\n+\t\t\t\"\n \t\treturn\n \tesac\n \tCOMPREPLY=()\n@@ -379,17 +379,16 @@ _git_apply ()\n \tlocal cur=\"${COMP_WORDS[COMP_CWORD]}\"\n \tcase \"$cur\" in\n \t--whitespace=*)\n-\t\tCOMPREPLY=($(compgen -W \"$__git_whitespacelist\" \\\n-\t\t\t-- \"${cur##--whitespace=}\"))\n+\t\t__gitcomp \"$__git_whitespacelist\" \"\" \"${cur##--whitespace=}\"\n \t\treturn\n \t\t;;\n \t--*)\n-\t\tCOMPREPLY=($(compgen -W \"\n+\t\t__gitcomp \"\n \t\t\t--stat --numstat --summary --check --index\n \t\t\t--cached --index-info --reverse --reject --unidiff-zero\n \t\t\t--apply --no-add --exclude=\n \t\t\t--whitespace= --inaccurate-eof --verbose\n-\t\t\t\" -- \"$cur\"))\n+\t\t\t\"\n \t\treturn\n \tesac\n \tCOMPREPLY=()\n@@ -400,9 +399,7 @@ _git_add ()\n \tlocal cur=\"${COMP_WORDS[COMP_CWORD]}\"\n \tcase \"$cur\" in\n \t--*)\n-\t\tCOMPREPLY=($(compgen -W \"\n-\t\t\t--interactive\n-\t\t\t\" -- \"$cur\"))\n+\t\t__gitcomp \"--interactive\"\n \t\treturn\n \tesac\n \tCOMPREPLY=()\n@@ -410,14 +407,12 @@ _git_add ()\n \n _git_branch ()\n {\n-\tlocal cur=\"${COMP_WORDS[COMP_CWORD]}\"\n-\tCOMPREPLY=($(compgen -W \"$(__git_refs)\" -- \"$cur\"))\n+\t__gitcomp \"$(__git_refs)\"\n }\n \n _git_checkout ()\n {\n-\tlocal cur=\"${COMP_WORDS[COMP_CWORD]}\"\n-\tCOMPREPLY=($(compgen -W \"$(__git_refs)\" -- \"$cur\"))\n+\t__gitcomp \"$(__git_refs)\"\n }\n \n _git_cherry_pick ()\n@@ -425,12 +420,10 @@ _git_cherry_pick ()\n \tlocal cur=\"${COMP_WORDS[COMP_CWORD]}\"\n \tcase \"$cur\" in\n \t--*)\n-\t\tCOMPREPLY=($(compgen -W \"\n-\t\t\t--edit --no-commit\n-\t\t\t\" -- \"$cur\"))\n+\t\t__gitcomp \"--edit --no-commit\"\n \t\t;;\n \t*)\n-\t\tCOMPREPLY=($(compgen -W \"$(__git_refs)\" -- \"$cur\"))\n+\t\t__gitcomp \"$(__git_refs)\"\n \t\t;;\n \tesac\n }\n@@ -440,10 +433,10 @@ _git_commit ()\n \tlocal cur=\"${COMP_WORDS[COMP_CWORD]}\"\n \tcase \"$cur\" in\n \t--*)\n-\t\tCOMPREPLY=($(compgen -W \"\n+\t\t__gitcomp \"\n \t\t\t--all --author= --signoff --verify --no-verify\n \t\t\t--edit --amend --include --only\n-\t\t\t\" -- \"$cur\"))\n+\t\t\t\"\n \t\treturn\n \tesac\n \tCOMPREPLY=()\n@@ -456,8 +449,7 @@ _git_diff ()\n \n _git_diff_tree ()\n {\n-\tlocal cur=\"${COMP_WORDS[COMP_CWORD]}\"\n-\tCOMPREPLY=($(compgen -W \"$(__git_refs)\" -- \"$cur\"))\n+\t__gitcomp \"$(__git_refs)\"\n }\n \n _git_fetch ()\n@@ -466,16 +458,15 @@ _git_fetch ()\n \n \tcase \"${COMP_WORDS[0]},$COMP_CWORD\" in\n \tgit-fetch*,1)\n-\t\tCOMPREPLY=($(compgen -W \"$(__git_remotes)\" -- \"$cur\"))\n+\t\t__gitcomp \"$(__git_remotes)\"\n \t\t;;\n \tgit,2)\n-\t\tCOMPREPLY=($(compgen -W \"$(__git_remotes)\" -- \"$cur\"))\n+\t\t__gitcomp \"$(__git_remotes)\"\n \t\t;;\n \t*)\n \t\tcase \"$cur\" in\n \t\t*:*)\n-\t\t\tcur=\"${cur#*:}\"\n-\t\t\tCOMPREPLY=($(compgen -W \"$(__git_refs)\" -- \"$cur\"))\n+\t\t\t__gitcomp \"$(__git_refs)\" \"\" \"${cur#*:}\"\n \t\t\t;;\n \t\t*)\n \t\t\tlocal remote\n@@ -483,7 +474,7 @@ _git_fetch ()\n \t\t\tgit-fetch) remote=\"${COMP_WORDS[1]}\" ;;\n \t\t\tgit)       remote=\"${COMP_WORDS[2]}\" ;;\n \t\t\tesac\n-\t\t\tCOMPREPLY=($(compgen -W \"$(__git_refs2 \"$remote\")\" -- \"$cur\"))\n+\t\t\t__gitcomp \"$(__git_refs2 \"$remote\")\"\n \t\t\t;;\n \t\tesac\n \t\t;;\n@@ -495,7 +486,7 @@ _git_format_patch ()\n \tlocal cur=\"${COMP_WORDS[COMP_CWORD]}\"\n \tcase \"$cur\" in\n \t--*)\n-\t\tCOMPREPLY=($(compgen -W \"\n+\t\t__gitcomp \"\n \t\t\t--stdout --attach --thread\n \t\t\t--output-directory\n \t\t\t--numbered --start-number\n@@ -503,7 +494,7 @@ _git_format_patch ()\n \t\t\t--signoff\n \t\t\t--in-reply-to=\n \t\t\t--full-index --binary\n-\t\t\t\" -- \"$cur\"))\n+\t\t\t\"\n \t\treturn\n \t\t;;\n \tesac\n@@ -512,8 +503,7 @@ _git_format_patch ()\n \n _git_ls_remote ()\n {\n-\tlocal cur=\"${COMP_WORDS[COMP_CWORD]}\"\n-\tCOMPREPLY=($(compgen -W \"$(__git_remotes)\" -- \"$cur\"))\n+\t__gitcomp \"$(__git_remotes)\"\n }\n \n _git_ls_tree ()\n@@ -526,13 +516,13 @@ _git_log ()\n \tlocal cur=\"${COMP_WORDS[COMP_CWORD]}\"\n \tcase \"$cur\" in\n \t--pretty=*)\n-\t\tCOMPREPLY=($(compgen -W \"\n+\t\t__gitcomp \"\n \t\t\toneline short medium full fuller email raw\n-\t\t\t\" -- \"${cur##--pretty=}\"))\n+\t\t\t\" \"\" \"${cur##--pretty=}\"\n \t\treturn\n \t\t;;\n \t--*)\n-\t\tCOMPREPLY=($(compgen -W \"\n+\t\t__gitcomp \"\n \t\t\t--max-count= --max-age= --since= --after=\n \t\t\t--min-age= --before= --until=\n \t\t\t--root --not --topo-order --date-order\n@@ -542,7 +532,7 @@ _git_log ()\n \t\t\t--author= --committer= --grep=\n \t\t\t--all-match\n \t\t\t--pretty= --name-status --name-only\n-\t\t\t\" -- \"$cur\"))\n+\t\t\t\"\n \t\treturn\n \t\t;;\n \tesac\n@@ -554,34 +544,31 @@ _git_merge ()\n \tlocal cur=\"${COMP_WORDS[COMP_CWORD]}\"\n \tcase \"${COMP_WORDS[COMP_CWORD-1]}\" in\n \t-s|--strategy)\n-\t\tCOMPREPLY=($(compgen -W \"$(__git_merge_strategies)\" -- \"$cur\"))\n+\t\t__gitcomp \"$(__git_merge_strategies)\"\n \t\treturn\n \tesac\n \tcase \"$cur\" in\n \t--strategy=*)\n-\t\tCOMPREPLY=($(compgen -W \"$(__git_merge_strategies)\" \\\n-\t\t\t-- \"${cur##--strategy=}\"))\n+\t\t__gitcomp \"$(__git_merge_strategies)\" \"\" \"${cur##--strategy=}\"\n \t\treturn\n \t\t;;\n \t--*)\n-\t\tCOMPREPLY=($(compgen -W \"\n+\t\t__gitcomp \"\n \t\t\t--no-commit --no-summary --squash --strategy\n-\t\t\t\" -- \"$cur\"))\n+\t\t\t\"\n \t\treturn\n \tesac\n-\tCOMPREPLY=($(compgen -W \"$(__git_refs)\" -- \"$cur\"))\n+\t__gitcomp \"$(__git_refs)\"\n }\n \n _git_merge_base ()\n {\n-\tlocal cur=\"${COMP_WORDS[COMP_CWORD]}\"\n-\tCOMPREPLY=($(compgen -W \"$(__git_refs)\" -- \"$cur\"))\n+\t__gitcomp \"$(__git_refs)\"\n }\n \n _git_name_rev ()\n {\n-\tlocal cur=\"${COMP_WORDS[COMP_CWORD]}\"\n-\tCOMPREPLY=($(compgen -W \"--tags --all --stdin\" -- \"$cur\"))\n+\t__gitcomp \"--tags --all --stdin\"\n }\n \n _git_pull ()\n@@ -590,10 +577,10 @@ _git_pull ()\n \n \tcase \"${COMP_WORDS[0]},$COMP_CWORD\" in\n \tgit-pull*,1)\n-\t\tCOMPREPLY=($(compgen -W \"$(__git_remotes)\" -- \"$cur\"))\n+\t\t__gitcomp \"$(__git_remotes)\"\n \t\t;;\n \tgit,2)\n-\t\tCOMPREPLY=($(compgen -W \"$(__git_remotes)\" -- \"$cur\"))\n+\t\t__gitcomp \"$(__git_remotes)\"\n \t\t;;\n \t*)\n \t\tlocal remote\n@@ -601,7 +588,7 @@ _git_pull ()\n \t\tgit-pull)  remote=\"${COMP_WORDS[1]}\" ;;\n \t\tgit)       remote=\"${COMP_WORDS[2]}\" ;;\n \t\tesac\n-\t\tCOMPREPLY=($(compgen -W \"$(__git_refs \"$remote\")\" -- \"$cur\"))\n+\t\t__gitcomp \"$(__git_refs \"$remote\")\"\n \t\t;;\n \tesac\n }\n@@ -612,10 +599,10 @@ _git_push ()\n \n \tcase \"${COMP_WORDS[0]},$COMP_CWORD\" in\n \tgit-push*,1)\n-\t\tCOMPREPLY=($(compgen -W \"$(__git_remotes)\" -- \"$cur\"))\n+\t\t__gitcomp \"$(__git_remotes)\"\n \t\t;;\n \tgit,2)\n-\t\tCOMPREPLY=($(compgen -W \"$(__git_remotes)\" -- \"$cur\"))\n+\t\t__gitcomp \"$(__git_remotes)\"\n \t\t;;\n \t*)\n \t\tcase \"$cur\" in\n@@ -625,11 +612,10 @@ _git_push ()\n \t\t\tgit-push)  remote=\"${COMP_WORDS[1]}\" ;;\n \t\t\tgit)       remote=\"${COMP_WORDS[2]}\" ;;\n \t\t\tesac\n-\t\t\tcur=\"${cur#*:}\"\n-\t\t\tCOMPREPLY=($(compgen -W \"$(__git_refs \"$remote\")\" -- \"$cur\"))\n+\t\t\t__gitcomp \"$(__git_refs \"$remote\")\" \"\" \"${cur#*:}\"\n \t\t\t;;\n \t\t*)\n-\t\t\tCOMPREPLY=($(compgen -W \"$(__git_refs2)\" -- \"$cur\"))\n+\t\t\t__gitcomp \"$(__git_refs2)\"\n \t\t\t;;\n \t\tesac\n \t\t;;\n@@ -640,29 +626,24 @@ _git_rebase ()\n {\n \tlocal cur=\"${COMP_WORDS[COMP_CWORD]}\"\n \tif [ -d .dotest ]; then\n-\t\tCOMPREPLY=($(compgen -W \"\n-\t\t\t--continue --skip --abort\n-\t\t\t\" -- \"$cur\"))\n+\t\t__gitcomp \"--continue --skip --abort\"\n \t\treturn\n \tfi\n \tcase \"${COMP_WORDS[COMP_CWORD-1]}\" in\n \t-s|--strategy)\n-\t\tCOMPREPLY=($(compgen -W \"$(__git_merge_strategies)\" -- \"$cur\"))\n+\t\t__gitcomp \"$(__git_merge_strategies)\"\n \t\treturn\n \tesac\n \tcase \"$cur\" in\n \t--strategy=*)\n-\t\tCOMPREPLY=($(compgen -W \"$(__git_merge_strategies)\" \\\n-\t\t\t-- \"${cur##--strategy=}\"))\n+\t\t__gitcomp \"$(__git_merge_strategies)\" \"\" \"${cur##--strategy=}\"\n \t\treturn\n \t\t;;\n \t--*)\n-\t\tCOMPREPLY=($(compgen -W \"\n-\t\t\t--onto --merge --strategy\n-\t\t\t\" -- \"$cur\"))\n+\t\t__gitcomp \"--onto --merge --strategy\"\n \t\treturn\n \tesac\n-\tCOMPREPLY=($(compgen -W \"$(__git_refs)\" -- \"$cur\"))\n+\t__gitcomp \"$(__git_refs)\"\n }\n \n _git_config ()\n@@ -824,8 +805,13 @@ _git_config ()\n _git_reset ()\n {\n \tlocal cur=\"${COMP_WORDS[COMP_CWORD]}\"\n-\tlocal opt=\"--mixed --hard --soft\"\n-\tCOMPREPLY=($(compgen -W \"$opt $(__git_refs)\" -- \"$cur\"))\n+\tcase \"$cur\" in\n+\t--*)\n+\t\t__gitcomp \"--mixed --hard --soft\"\n+\t\treturn\n+\t\t;;\n+\tesac\n+\t__gitcomp \"$(__git_refs)\"\n }\n \n _git_show ()\n@@ -833,13 +819,13 @@ _git_show ()\n \tlocal cur=\"${COMP_WORDS[COMP_CWORD]}\"\n \tcase \"$cur\" in\n \t--pretty=*)\n-\t\tCOMPREPLY=($(compgen -W \"\n+\t\t__gitcomp \"\n \t\t\toneline short medium full fuller email raw\n-\t\t\t\" -- \"${cur##--pretty=}\"))\n+\t\t\t\" \"\" \"${cur##--pretty=}\"\n \t\treturn\n \t\t;;\n \t--*)\n-\t\tCOMPREPLY=($(compgen -W \"--pretty=\" -- \"$cur\"))\n+\t\t__gitcomp \"--pretty=\"\n \t\treturn\n \t\t;;\n \tesac\n@@ -906,32 +892,38 @@ _git ()\n _gitk ()\n {\n \tlocal cur=\"${COMP_WORDS[COMP_CWORD]}\"\n-\tCOMPREPLY=($(compgen -W \"--all $(__git_refs)\" -- \"$cur\"))\n+\tcase \"$cur\" in\n+\t--*)\n+\t\t__gitcomp \"--not --all\"\n+\t\treturn\n+\t\t;;\n+\tesac\n+\t__gitcomp \"$(__git_refs)\"\n }\n \n complete -o default -o nospace -F _git git\n-complete -o default            -F _gitk gitk\n-complete -o default            -F _git_am git-am\n-complete -o default            -F _git_apply git-apply\n-complete -o default            -F _git_branch git-branch\n-complete -o default            -F _git_checkout git-checkout\n-complete -o default            -F _git_cherry_pick git-cherry-pick\n-complete -o default            -F _git_commit git-commit\n+complete -o default -o nospace -F _gitk gitk\n+complete -o default -o nospace -F _git_am git-am\n+complete -o default -o nospace -F _git_apply git-apply\n+complete -o default -o nospace -F _git_branch git-branch\n+complete -o default -o nospace -F _git_checkout git-checkout\n+complete -o default -o nospace -F _git_cherry_pick git-cherry-pick\n+complete -o default -o nospace -F _git_commit git-commit\n complete -o default -o nospace -F _git_diff git-diff\n-complete -o default            -F _git_diff_tree git-diff-tree\n+complete -o default -o nospace -F _git_diff_tree git-diff-tree\n complete -o default -o nospace -F _git_fetch git-fetch\n complete -o default -o nospace -F _git_format_patch git-format-patch\n complete -o default -o nospace -F _git_log git-log\n-complete -o default            -F _git_ls_remote git-ls-remote\n+complete -o default -o nospace -F _git_ls_remote git-ls-remote\n complete -o default -o nospace -F _git_ls_tree git-ls-tree\n-complete -o default            -F _git_merge git-merge\n-complete -o default            -F _git_merge_base git-merge-base\n-complete -o default            -F _git_name_rev git-name-rev\n+complete -o default -o nospace -F _git_merge git-merge\n+complete -o default -o nospace -F _git_merge_base git-merge-base\n+complete -o default -o nospace -F _git_name_rev git-name-rev\n complete -o default -o nospace -F _git_pull git-pull\n complete -o default -o nospace -F _git_push git-push\n-complete -o default            -F _git_rebase git-rebase\n-complete -o default            -F _git_config git-config\n-complete -o default            -F _git_reset git-reset\n+complete -o default -o nospace -F _git_rebase git-rebase\n+complete -o default -o nospace -F _git_config git-config\n+complete -o default -o nospace -F _git_reset git-reset\n complete -o default -o nospace -F _git_show git-show\n complete -o default -o nospace -F _git_log git-show-branch\n complete -o default -o nospace -F _git_log git-whatchanged\n@@ -941,19 +933,19 @@ complete -o default -o nospace -F _git_log git-whatchanged\n # included the '.exe' suffix.\n #\n if [ Cygwin = \"$(uname -o 2>/dev/null)\" ]; then\n-complete -o default            -F _git_add git-add.exe\n-complete -o default            -F _git_apply git-apply.exe\n+complete -o default -o nospace -F _git_add git-add.exe\n+complete -o default -o nospace -F _git_apply git-apply.exe\n complete -o default -o nospace -F _git git.exe\n-complete -o default            -F _git_branch git-branch.exe\n+complete -o default -o nospace -F _git_branch git-branch.exe\n complete -o default -o nospace -F _git_diff git-diff.exe\n complete -o default -o nospace -F _git_diff_tree git-diff-tree.exe\n complete -o default -o nospace -F _git_format_patch git-format-patch.exe\n complete -o default -o nospace -F _git_log git-log.exe\n complete -o default -o nospace -F _git_ls_tree git-ls-tree.exe\n-complete -o default            -F _git_merge_base git-merge-base.exe\n-complete -o default            -F _git_name_rev git-name-rev.exe\n+complete -o default -o nospace -F _git_merge_base git-merge-base.exe\n+complete -o default -o nospace -F _git_name_rev git-name-rev.exe\n complete -o default -o nospace -F _git_push git-push.exe\n-complete -o default            -F _git_config git-config\n+complete -o default -o nospace -F _git_config git-config\n complete -o default -o nospace -F _git_show git-show.exe\n complete -o default -o nospace -F _git_log git-show-branch.exe\n complete -o default -o nospace -F _git_log git-whatchanged.exe\n-- \n1.5.0.rc3.22.g5057\n"}]}