mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-05-31 12:21:19 -03:00
completions/git: define function before use
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user