mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-22 14:43:55 +08:00
Do use autogenerated completions for external git subcommands
Some third party Git tools provide a man page, which we can at least use for completing options. The old logic excluded all generated completions for Git subcommands. Instead, try to load completions for all available external subcommands. We can use $PATH/git-* because /bin/git-add and friends were removed in Git 1.6.0 in 2008. Closes #4358 (the "git-foo" wrapping was added in #7652)
This commit is contained in:
parent
abb59a6ec9
commit
29ee4d318d
|
@ -360,7 +360,7 @@ Completions
|
||||||
- The ``make`` completions no longer second-guess make's file detection, fixing target completion in some cases (:issue:`7535`).
|
- The ``make`` completions no longer second-guess make's file detection, fixing target completion in some cases (:issue:`7535`).
|
||||||
- The command completions now correctly print the description even if the command was fully matched (like in ``ls<TAB>``).
|
- The command completions now correctly print the description even if the command was fully matched (like in ``ls<TAB>``).
|
||||||
- The ``set`` completions no longer hide variables starting with ``__``, they are sorted last instead.
|
- The ``set`` completions no longer hide variables starting with ``__``, they are sorted last instead.
|
||||||
- Completion scripts for custom Git subcommands like ``git-xyz`` are now loaded with Git completions. The completions can now be defined directly on the subcommand (using ``complete git-xyz``), and completion for ``git xyz`` will work. (:issue:`7075`, :issue:`7652`)
|
- Completion scripts for custom Git subcommands like ``git-xyz`` are now loaded with Git completions. The completions can now be defined directly on the subcommand (using ``complete git-xyz``), and completion for ``git xyz`` will work. (:issue:`7075`, :issue:`7652`, :issue:`4358`)
|
||||||
|
|
||||||
Changes not visible to users
|
Changes not visible to users
|
||||||
----------------------------
|
----------------------------
|
||||||
|
|
|
@ -1909,26 +1909,18 @@ function __fish_git_complete_custom_command -a subcommand
|
||||||
complete -C "git-$subcommand $subcommand_args "(commandline -ct)
|
complete -C "git-$subcommand $subcommand_args "(commandline -ct)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Get the path to the generated completions
|
|
||||||
# If $XDG_DATA_HOME is set, that's it, if not, it will be removed and ~/.local/share will remain.
|
|
||||||
set -l generated_path $XDG_DATA_HOME/fish/generated_completions ~/.local/share/fish/generated_completions
|
|
||||||
|
|
||||||
# We don't want to modify $fish_complete_path here, so we make a copy.
|
|
||||||
set -l complete_dirs $fish_complete_path
|
|
||||||
|
|
||||||
# Remove the path to the generated completions if it is in the list
|
|
||||||
set -l ind (contains -i -- $generated_path[1] $complete_dirs); and set -e complete_dirs[$ind]
|
|
||||||
|
|
||||||
# source git-* commands' autocompletion file if exists
|
# source git-* commands' autocompletion file if exists
|
||||||
set -l __fish_git_custom_commands_completion
|
set -l __fish_git_custom_commands_completion
|
||||||
for git_ext in $complete_dirs/git-*.fish
|
for file in $PATH/git-*
|
||||||
# ignore this completion as executable does not exists
|
not command -q $file
|
||||||
set -l subcommand (string replace -r '.*/git-([^/]*)\.fish' '$1' $git_ext)
|
|
||||||
not command -q git-$subcommand
|
|
||||||
and continue
|
and continue
|
||||||
# already sourced this git-* completion file from some other dir
|
|
||||||
|
set -l subcommand (string replace -r -- '.*/git-([^/]*)$' '$1' $file)
|
||||||
|
|
||||||
|
# Already seen this command earlier in $PATH.
|
||||||
contains -- $subcommand $__fish_git_custom_commands_completion
|
contains -- $subcommand $__fish_git_custom_commands_completion
|
||||||
and continue
|
and continue
|
||||||
|
|
||||||
complete -C "git-$subcommand " >/dev/null
|
complete -C "git-$subcommand " >/dev/null
|
||||||
if [ (complete git-$subcommand | count) -gt 0 ]
|
if [ (complete git-$subcommand | count) -gt 0 ]
|
||||||
complete git -f -n "__fish_git_using_command $subcommand" -a "(__fish_git_complete_custom_command $subcommand)"
|
complete git -f -n "__fish_git_using_command $subcommand" -a "(__fish_git_complete_custom_command $subcommand)"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user