{"thread":{"id":"32363","subject":"[PATCH v2] git-completion.bash: add support for path completion","startedAt":"2012-12-16T22:20:55Z","lastAt":"2012-12-16T22:20:55Z","messageCount":1,"participants":["Manlio Perillo"],"isPatch":true,"patchVersion":2,"patchTotal":null},"messages":[{"id":"204990","messageId":"1355696455-11135-1-git-send-email-manlio.perillo@gmail.com","threadId":"32363","inReplyTo":null,"subject":"[PATCH v2] git-completion.bash: add support for path completion","fromName":"Manlio Perillo","fromEmail":"manlio.perillo@gmail.com","sentAt":"2012-12-16T22:20:55Z","receivedAt":"2012-12-16T22:20:55Z","isPatch":true,"sender":{"key":"manlio.perillo@gmail.com","avatar":"https://avatars.githubusercontent.com/u/6217088?v=4"},"body":"The git-completion.bash script did not implemented full support for\ncompletion, for git commands that operate on files from the current\nworking directory or the index.\n\nFor these commands, only options completion was available.\n\nFull support for completion is now implemented, for git commands where\nthe non-option arguments always refer to paths on the current working\ndirectory or the index, as the follow:\n\n* the path completion for the \"git mv\" and \"git rm\" commands is provided\n  using \"git ls-files --exclude-standard\"\n\n* the path completion for the \"git add\" command is provided using\n  \"git ls-files --exclude-standard -o -m\"\n\n* the path completion for the \"git clean\" command is provided using\n  \"git ls-files --exclude-standard -o\"\n\n* the path completion for the \"git commit\" command is provides using\n  \"git diff-index --name-only HEAD\"\n\nSigned-off-by: Manlio Perillo <manlio.perillo@gmail.com>\n---\n\nUpdated the script documentation.\n\n contrib/completion/git-completion.bash | 40 +++++++++++++++++++++++-----------\n 1 file changed, 27 insertions(+), 13 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 0b77eb1..3bd7fc8 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -13,6 +13,7 @@\n #    *) .git/remotes file names\n #    *) git 'subcommands'\n #    *) tree paths within 'ref:path/to/file' expressions\n+#    *) working directory and index file names\n #    *) common --long-options\n #\n # To use these routines:\n@@ -233,6 +234,25 @@ __gitcomp_nl ()\n \tCOMPREPLY=($(compgen -P \"${2-}\" -S \"${4- }\" -W \"$1\" -- \"${3-$cur}\"))\n }\n \n+__git_files ()\n+{\n+\tlocal dir=\"$(__gitdir)\"\n+\tif [ -d \"$dir\" ]; then\n+\t\tgit --git-dir=\"$dir\" ls-files --exclude-standard $*\n+\t\treturn\n+\tfi\n+}\n+\n+# Return all staged files with modification from current HEAD\n+__git_commit_files ()\n+{\n+\tlocal dir=\"$(__gitdir)\"\n+\tif [ -d \"$dir\" ]; then\n+\t\tgit --git-dir=\"$dir\" diff-index --name-only HEAD\n+\t\treturn\n+\tfi\n+}\n+\n __git_heads ()\n {\n \tlocal dir=\"$(__gitdir)\"\n@@ -770,8 +790,6 @@ _git_apply ()\n \n _git_add ()\n {\n-\t__git_has_doubledash && return\n-\n \tcase \"$cur\" in\n \t--*)\n \t\t__gitcomp \"\n@@ -780,7 +798,8 @@ _git_add ()\n \t\t\t\"\n \t\treturn\n \tesac\n-\tCOMPREPLY=()\n+\t# XXX should we care for --update and --all options ?\n+\t__gitcomp_nl \"$(__git_files -o -m)\" \"\" \"$cur\" \"\"\n }\n \n _git_archive ()\n@@ -930,15 +949,14 @@ _git_cherry_pick ()\n \n _git_clean ()\n {\n-\t__git_has_doubledash && return\n-\n \tcase \"$cur\" in\n \t--*)\n \t\t__gitcomp \"--dry-run --quiet\"\n \t\treturn\n \t\t;;\n \tesac\n-\tCOMPREPLY=()\n+\t# TODO: check for -x option\n+\t__gitcomp_nl \"$(__git_files -o)\" \"\" \"$cur\" \"\"\n }\n \n _git_clone ()\n@@ -969,8 +987,6 @@ _git_clone ()\n \n _git_commit ()\n {\n-\t__git_has_doubledash && return\n-\n \tcase \"$cur\" in\n \t--cleanup=*)\n \t\t__gitcomp \"default strip verbatim whitespace\n@@ -998,7 +1014,7 @@ _git_commit ()\n \t\t\t\"\n \t\treturn\n \tesac\n-\tCOMPREPLY=()\n+\t__gitcomp_nl \"$(__git_commit_files)\" \"\" \"$cur\" \"\"\n }\n \n _git_describe ()\n@@ -1362,7 +1378,7 @@ _git_mv ()\n \t\treturn\n \t\t;;\n \tesac\n-\tCOMPREPLY=()\n+\t__gitcomp_nl \"$(__git_files)\" \"\" \"$cur\" \"\"\n }\n \n _git_name_rev ()\n@@ -2068,15 +2084,13 @@ _git_revert ()\n \n _git_rm ()\n {\n-\t__git_has_doubledash && return\n-\n \tcase \"$cur\" in\n \t--*)\n \t\t__gitcomp \"--cached --dry-run --ignore-unmatch --quiet\"\n \t\treturn\n \t\t;;\n \tesac\n-\tCOMPREPLY=()\n+\t__gitcomp_nl \"$(__git_files)\" \"\" \"$cur\" \"\"\n }\n \n _git_shortlog ()\n-- \n1.8.1.rc1.18.g9db0d25\n"}]}