{"thread":{"id":"60698","subject":"[PATCH 1/1] completion: dir-type optargs for am, format-patch","startedAt":"2024-01-07T21:42:10Z","lastAt":"2024-01-08T18:38:03Z","messageCount":2,"participants":["Britton Leo Kerin","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":1},"messages":[{"id":"486381","messageId":"8a8dfcfc-3369-42b8-8387-f1af33202b16@smtp-relay.sendinblue.com","threadId":"60698","inReplyTo":"20240107214200.29684-1-britton.kerin@gmail.com","subject":"[PATCH 1/1] completion: dir-type optargs for am, format-patch","fromName":"Britton Leo Kerin","fromEmail":"britton.kerin@gmail.com","sentAt":"2024-01-07T21:42:00Z","receivedAt":"2024-01-07T21:42:10Z","isPatch":true,"sender":{"key":"britton.kerin@gmail.com","avatar":"https://avatars.githubusercontent.com/u/7434164?v=4"},"body":"Signed-off-by: Britton Leo Kerin <britton.kerin@gmail.com>\n---\n contrib/completion/git-completion.bash | 38 ++++++++++++++++++++++++++\n 1 file changed, 38 insertions(+)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 185b47d802..c3b0a3699c 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -1356,6 +1356,30 @@ __git_count_arguments ()\n \tprintf \"%d\" $c\n }\n \n+\n+# Complete actual dir (not pathspec), respecting any -C options.\n+#\n+# Usage: __git_complete_refs [<option>]...\n+# --cur=<word>: The current dir to be completed.  Defaults to the current word.\n+__git_complete_dir ()\n+{\n+\tlocal cur_=\"$cur\"\n+\n+\twhile test $# != 0; do\n+\t\tcase \"$1\" in\n+\t\t--cur=*)\tcur_=\"${1##--cur=}\" ;;\n+\t\t*)\t\treturn 1 ;;\n+\t\tesac\n+\t\tshift\n+\tdone\n+\n+\tlocal context_dir=$(__git rev-parse --show-toplevel --show-prefix 2>/dev/null | paste -s -d '/' 2>/dev/null)\n+\t[ -d \"$context_dir\" ] || return\n+\n+\tCOMPREPLY=$(cd $context_dir 2>/dev/null && compgen -d -- \"$cur_\")\n+}\n+\n+\n __git_whitespacelist=\"nowarn warn error error-all fix\"\n __git_patchformat=\"mbox stgit stgit-series hg mboxrd\"\n __git_showcurrentpatch=\"diff raw\"\n@@ -1374,6 +1398,10 @@ _git_am ()\n \t\t__gitcomp \"$__git_whitespacelist\" \"\" \"${cur##--whitespace=}\"\n \t\treturn\n \t\t;;\n+\t--directory=*)\n+\t\t__git_complete_dir --cur=\"${cur##--directory=}\"\n+\t\treturn\n+\t\t;;\n \t--patch-format=*)\n \t\t__gitcomp \"$__git_patchformat\" \"\" \"${cur##--patch-format=}\"\n \t\treturn\n@@ -1867,7 +1895,17 @@ __git_format_patch_extra_options=\"\n \n _git_format_patch ()\n {\n+\tcase \"$prev,$cur\" in\n+\t-o,*)\n+\t\t__git_complete_dir\n+\t\treturn\n+\t\t;;\n+\tesac\n \tcase \"$cur\" in\n+\t--output-directory=*)\n+\t\t__git_complete_dir --cur=\"${cur##--output-directory=}\"\n+\t\treturn\n+\t\t;;\n \t--thread=*)\n \t\t__gitcomp \"\n \t\t\tdeep shallow\n-- \n2.43.0\n\n\n"},{"id":"486405","messageId":"xmqqttnnk6ws.fsf@gitster.g","threadId":"60698","inReplyTo":"8a8dfcfc-3369-42b8-8387-f1af33202b16@smtp-relay.sendinblue.com","subject":"Re: [PATCH 1/1] completion: dir-type optargs for am, format-patch","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2024-01-08T18:37:55Z","receivedAt":"2024-01-08T18:38:03Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Britton Leo Kerin\" <britton.kerin@gmail.com> writes:\n\n> +\tlocal context_dir=$(__git rev-parse --show-toplevel --show-prefix 2>/dev/null | paste -s -d '/' 2>/dev/null)\n\nIs there a practical difference with the above with\n\n\tcontext_dir=$(pwd)\n\nother than that it will give an empty string outside a git working tree?\n\nIf not, I suspect\n\n\tlocal inside\n\n\tinside=$(__git rev-parse --is-inside-work-tree) &&\n\ttest \"$inside\" = true || return\n\n\tlocal context_dir=$(pwd)\n\nmight be clearer on the intent.\n\n> +\t[ -d \"$context_dir\" ] || return\n> +\n> +\tCOMPREPLY=$(cd $context_dir 2>/dev/null && compgen -d -- \"$cur_\")\n\nCan $context_dir contain $IFS whitespaces here?\n\n> +}\n"}]}