From 77941ea823cb685c2f74b0f9f778e968803e8af5 Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Tue, 27 Sep 2022 14:17:59 -0500 Subject: [PATCH] Completions: add `git xxx --sort` completions The list of subcommands that emit a list of refs when executed bare may or may not be complete; I just put the ones I know of. --- share/completions/git.fish | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/share/completions/git.fish b/share/completions/git.fish index 424f6c557..7567ce128 100644 --- a/share/completions/git.fish +++ b/share/completions/git.fish @@ -2304,6 +2304,29 @@ complete -f -c git -n '__fish_git_using_command for-each-ref' -x -l contains -d complete -f -c git -n '__fish_git_using_command for-each-ref' -x -l no-contains -d "Only list refs not containing the specified commit" -ka '(__fish_git_commits)' complete -f -c git -n '__fish_git_using_command for-each-ref' -x -l ignore-case -d "Sorting and filtering refs are case insensitive" +### subcommands supporting --sort (XXX: list may not be complete!) +set -l sortcommands branch for-each-ref tag +# A list of keys one could reasonably sort refs by. This isn't the list of all keys that +# can be used as any git internal key for a ref may be used here, sorted by binary value. +function __fish_git_sort_keys + echo -objectsize\tSize of branch or commit + echo -authordate\tWhen the latest commit was actually made + echo -commiterdate\tWhen the branch was last committed or rebased + echo -creatordate\tWhen the latest commit or tag was created + echo -creator\tThe name of the commit author + echo -objectname\tThe complete SHA1 + echo -objectname:short\tThe shortest non-ambiguous SHA1 + echo -refname\tThe complete, unambiguous git ref name + echo -refname:short\tThe shortest non-ambiguous ref name + echo -author\tThe name of the author of the latest commit + echo -committer\tThe name of the person who committed latest + echo -tagger\tThe name of the person who created the tag + echo -authoremail\tThe email of the author of the latest commit + echo -commiteremail\tThe email of the person who committed last + echo -taggeremail\tThe email of the person who created the tag +end +complete -f -c git -n "__fish_seen_subcommand_from $sortcommands" -l sort -d 'Sort results by' -a "(__fish_git_sort_keys)" + ## Custom commands (git-* commands installed in the PATH) complete -c git -n __fish_git_needs_command -a '(__fish_git_custom_commands)' -d 'Custom command'