From e50805646ea7c0a3effb1184e41ff3614c8d7509 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Mon, 12 Jul 2021 23:41:28 +0200 Subject: [PATCH] completions/git: define function before use --- share/completions/git.fish | 19 ++++++++++--------- tests/checks/git.fish | 4 ++++ 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/share/completions/git.fish b/share/completions/git.fish index 98f2eb501..92e7eaef1 100644 --- a/share/completions/git.fish +++ b/share/completions/git.fish @@ -593,13 +593,6 @@ end # So instead, we store the aliases in global variables, named after the alias, containing the command. # This is because alias:command is an n:1 mapping (an alias can only have one corresponding command, # but a command can be aliased multiple times) -git config -z --get-regexp 'alias\..*' | while read -lz alias cmdline - set -l command (__fish_git_aliased_command $cmdline) - string match -q --regex '\w+' -- $command; or continue - # Git aliases can contain chars that variable names can't - escape them. - set -l alias (string replace 'alias.' '' -- $alias | string escape --style=var) - set -g __fish_git_alias_$alias $command -end # Approximately duplicates the logic from https://github.com/git/git/blob/d486ca60a51c9cb1fe068803c3f540724e95e83a/contrib/completion/git-completion.bash#L1130 # The Git script also finds aliases that reference other aliases via a loop but this is fine for a PoC @@ -607,9 +600,9 @@ function __fish_git_aliased_command for word in (string split ' ' -- $argv) switch $word case !gitk gitk - echo "gitk" + echo gitk return - # Adding " to the list + # Adding " to the list case '!*' '-*' '*=*' git '()' '{' : '\'*' '"*' continue case '*' @@ -619,6 +612,14 @@ function __fish_git_aliased_command end end +git config -z --get-regexp 'alias\..*' | while read -lz alias cmdline + set -l command (__fish_git_aliased_command $cmdline) + string match -q --regex '\w+' -- $command; or continue + # Git aliases can contain chars that variable names can't - escape them. + set -l alias (string replace 'alias.' '' -- $alias | string escape --style=var) + set -g __fish_git_alias_$alias $command +end + function __fish_git_using_command set -l cmd (__fish_git_needs_command) test -z "$cmd" diff --git a/tests/checks/git.fish b/tests/checks/git.fish index f0158177c..6f1cafd8c 100644 --- a/tests/checks/git.fish +++ b/tests/checks/git.fish @@ -36,6 +36,10 @@ touch foo complete -C'git add ' #CHECK: foo Untracked file +git config alias.s status +complete 'git s --s' +# CHECK --short + # Note: We can't rely on the initial branch because that might be # "master", or it could be changed to something else in future! git checkout -b newbranch >/dev/null 2>&1