mirror of
https://github.com/fish-shell/fish-shell
synced 2024-11-10 15:14:44 +00:00
Revert "completions/git: cache subcommand computation"
Commit ad9b4290e
optimized git completions by adding a completion that would
run on every completion request, which allows to precompute data used by
other completion entries. Unfortunately, the completion entry is not run
when the commandline contains a flag like `git -C`. If we didn't
already load git.fish, we'd error. Additionally, we got false positive
completions for `git diff -c`.
So this hack was a very bad idea. We should optimize in another way.
This commit is contained in:
parent
b73091b27b
commit
fee5a9125a
3 changed files with 41 additions and 33 deletions
|
@ -26,6 +26,7 @@ Improved prompts
|
|||
Completions
|
||||
^^^^^^^^^^^
|
||||
- Added completions for:
|
||||
- A regression in 3.5.0 caused completions for ``git -C`` to print errors, which has been fixed.
|
||||
|
||||
|
||||
Improved terminal support
|
||||
|
|
|
@ -563,6 +563,25 @@ function __fish_git_ranges
|
|||
end
|
||||
end
|
||||
|
||||
function __fish_git_needs_command
|
||||
# Figure out if the current invocation already has a command.
|
||||
set -l cmd (commandline -opc)
|
||||
set -e cmd[1]
|
||||
argparse -s (__fish_git_global_optspecs) -- $cmd 2>/dev/null
|
||||
or return 0
|
||||
# These flags function as commands, effectively.
|
||||
set -q _flag_version; and return 1
|
||||
set -q _flag_html_path; and return 1
|
||||
set -q _flag_man_path; and return 1
|
||||
set -q _flag_info_path; and return 1
|
||||
if set -q argv[1]
|
||||
# Also print the command, so this can be used to figure out what it is.
|
||||
echo $argv[1]
|
||||
return 1
|
||||
end
|
||||
return 0
|
||||
end
|
||||
|
||||
function __fish_git_config_keys
|
||||
# Print already defined config values first
|
||||
# Config keys may span multiple lines, so parse using null char
|
||||
|
@ -614,12 +633,19 @@ git config -z --get-regexp 'alias\..*' | while read -lz alias cmdline
|
|||
set -g __fish_git_alias_$alias $command $cmdline
|
||||
end
|
||||
|
||||
function __fish_git_needs_command
|
||||
$__fish_git_needs_command
|
||||
end
|
||||
|
||||
function __fish_git_using_command
|
||||
contains $__fish_git_subcommand $argv
|
||||
set -l cmd (__fish_git_needs_command)
|
||||
test -z "$cmd"
|
||||
and return 1
|
||||
contains -- $cmd $argv
|
||||
and return 0
|
||||
|
||||
# Check aliases.
|
||||
set -l varname __fish_git_alias_(string escape --style=var -- $cmd)
|
||||
set -q $varname
|
||||
and contains -- $$varname[1][1] $argv
|
||||
and return 0
|
||||
return 1
|
||||
end
|
||||
|
||||
function __fish_git_contains_opt
|
||||
|
@ -630,8 +656,10 @@ function __fish_git_contains_opt
|
|||
|
||||
# Now check the alias
|
||||
argparse s= -- $argv
|
||||
if set -q __fish_git_expanded_alias[1]
|
||||
echo -- $__fish_git_expanded_alias | read -lat toks
|
||||
set -l cmd (__fish_git_needs_command)
|
||||
set -l varname __fish_git_alias_(string escape --style=var -- $cmd)
|
||||
if set -q $varname
|
||||
echo -- $$varname | read -lat toks
|
||||
set toks (string replace -r '(-.*)=.*' '' -- $toks)
|
||||
for i in $argv
|
||||
if contains -- --$i $toks
|
||||
|
@ -2267,29 +2295,3 @@ for file in $PATH/git-*
|
|||
complete -c git -f -n "__fish_git_using_command $subcommand" -a "(__fish_git_complete_custom_command $subcommand)"
|
||||
set -a __fish_git_custom_commands_completion $subcommand
|
||||
end
|
||||
|
||||
complete -c git -f -a '(
|
||||
set -g __fish_git_needs_command true
|
||||
set -g __fish_git_subcommand ""
|
||||
set -g __fish_git_expanded_alias
|
||||
|
||||
set -l cmd (commandline -opc)
|
||||
set -e cmd[1]
|
||||
argparse -s (__fish_git_global_optspecs) -- $cmd 2>/dev/null
|
||||
or return
|
||||
|
||||
if set -q argv[1] || set -q _flag_version || set -q _flag_html_path || set -q _flag_man_path || set -q _flag_info_path
|
||||
set __fish_git_needs_command false
|
||||
end
|
||||
|
||||
if set -q argv[1]
|
||||
set -l subcommand $argv[1]
|
||||
# TODO Expand recursive aliases.
|
||||
set -l varname __fish_git_alias_(string escape --style=var -- $subcommand)
|
||||
if set -q $varname
|
||||
set -g __fish_git_expanded_alias $$varname
|
||||
set subcommand $__fish_git_expanded_alias[1]
|
||||
end
|
||||
set -g __fish_git_subcommand "$subcommand"
|
||||
end
|
||||
)'
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
# e.g. the fish_git_prompt variable handlers test `status is-interactive`.
|
||||
#REQUIRES: command -v git
|
||||
|
||||
set -g fish (status fish-path)
|
||||
|
||||
# Tests run from git (e.g. git rebase --exec 'ninja test'...) inherit a weird git environment.
|
||||
# Ensure that no git environment variables are inherited.
|
||||
for varname in (set -x | string match 'GIT_*' | string replace -r ' .*' '')
|
||||
|
@ -134,3 +136,6 @@ test "$(complete -C'git re ')" = "$(complete -C'git restore --staged ')"
|
|||
or begin
|
||||
echo -- Oops re completes unlike restore --staged
|
||||
end
|
||||
|
||||
$fish -c 'complete -C "git -C ./.gi"'
|
||||
# CHECK: ./.git/ Directory
|
||||
|
|
Loading…
Reference in a new issue