-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Add fish completion support #4605
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lalvarezt
wants to merge
49
commits into
junegunn:master
Choose a base branch
from
lalvarezt:fish-completion
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+908
−108
Open
Changes from 32 commits
Commits
Show all changes
49 commits
Select commit
Hold shift + click to select a range
afa4d96
Add fish completion support
lalvarezt 0e3e405
Fix parsing of opts variables with quoted values containing spaces
lalvarezt 1d01c7f
Add file-only completion and walker/opts customization
lalvarezt 7a32421
Fix tmux detection, add option prefix handling
lalvarezt 156205d
Remove telnet,ssh,set,etc. handling in favor on native fish completion
lalvarezt 509b71f
Dropped tmux support for now, better completion handling
lalvarezt 53343fd
Add native completion commands and configurable fallback mode
lalvarezt 027daea
Escape trigger and improve path handling, and many other minor tweaks
lalvarezt 8b5b0d1
Rudimentary fish test setup
lalvarezt a4779d1
Make behavior consistent with bash/zsh, escape not quote. Load helper…
lalvarezt f555556
Add more tests
lalvarezt 39484f5
Make trigger the same as other shells, fix error in tokenize deprecat…
lalvarezt e41bf94
Remove FZF_COMPLETION_*_WALKER variables in favor of setting FZF_COMP…
lalvarezt d9f47bc
Add additional native command
lalvarezt 6b29404
Remove redundant checks, fix typo
lalvarezt 5631ed4
Simplify fzf-completion, generic_path_completion, complete_native, an…
lalvarezt e7bfdc4
Fix completion behavior
lalvarezt a17a7b0
Make fzf completion work only with trigger
lalvarezt af8fd08
Add command completion
lalvarezt b9d0632
Use colums for better alignment native completion support
lalvarezt 6709883
Add command and flag completion tests
lalvarezt b74c6f0
Early exit if no trigger
lalvarezt c384e0d
Add multi-select for native commands
lalvarezt a12868a
Add equal option completion test
lalvarezt 9c81c5e
Code refactoring by bitraid
lalvarezt 3b38a0e
Make test_option_equals_completion more robust to capture --opt= pref…
lalvarezt e62bbdc
Remove -o option from column, BSD and Linux compliant
lalvarezt e592ce7
Update compatibility matrix for test_option_equals_completion
lalvarezt ea56270
Add more cases
lalvarezt 0dec399
Simplify complete native with column as suggested by bitraid
lalvarezt 69e7e98
Make all fields searchable when column alignment is used
lalvarezt 5f31af9
Remove duplicated call, this is handled in completion.fish
lalvarezt bf2a5b1
Add missing eval
lalvarezt 866a6e8
Split tests and formalize for every shell the expected response
lalvarezt 854d67a
Cleanup duplicated tests, and promote to all instead of just fish
lalvarezt a350581
Fix RuboCop errors
junegunn cca8f47
Refactor test to be more specific
lalvarezt e9d7991
Tweak execution order for additional flexibility when defining native…
lalvarezt a25149a
Updated README
lalvarezt 762f2f0
Fix missing export flag
lalvarezt 241c21b
Improvements by bitraid
lalvarezt 7c45371
Fix some leftovers
lalvarezt 3439f2b
Reversing incorrect behavior
lalvarezt 57be384
Improvements by bitraid
lalvarezt 2351ee8
Add more binaries as default (from bash completion list)
lalvarezt 372b969
Make fish scripts independent and integrate them into update.sh
lalvarezt 01ab3f3
Fix indent issues
lalvarezt 0816ed1
More indent group
lalvarezt 1efbdf7
Update install script to support fish
lalvarezt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,179 @@ | ||
| # ____ ____ | ||
| # / __/___ / __/ | ||
| # / /_/_ / / /_ | ||
| # / __/ / /_/ __/ | ||
| # /_/ /___/_/ completion.fish | ||
| # | ||
| # - $FZF_COMPLETION_TRIGGER (default: '**') | ||
| # - $FZF_COMPLETION_OPTS (default: empty) | ||
| # - $FZF_COMPLETION_PATH_OPTS (default: empty) | ||
| # - $FZF_COMPLETION_DIR_OPTS (default: empty) | ||
| # - $FZF_COMPLETION_FILE_OPTS (default: empty) | ||
| # - $FZF_COMPLETION_DIR_COMMANDS (default: cd pushd rmdir) | ||
| # - $FZF_COMPLETION_FILE_COMMANDS (default: cat head tail less more nano) | ||
| # - $FZF_COMPLETION_NATIVE_COMMANDS (default: ssh telnet set functions type) | ||
|
|
||
| function fzf_completion_setup | ||
| # Load helper functions | ||
| fzf_key_bindings | ||
|
|
||
| # Use complete builtin for specific commands | ||
| function __fzf_complete_native | ||
| set -l result | ||
| if type -q column | ||
| set -lx -- FZF_DEFAULT_OPTS (__fzf_defaults "--reverse" \ | ||
| $FZF_COMPLETION_OPTS $argv[2..-1] --accept-nth=1) | ||
| set result (eval complete -C \"$argv[1]\" \| column -t -s \\t \| (__fzfcmd)) | ||
| else | ||
| set -lx -- FZF_DEFAULT_OPTS (__fzf_defaults "--reverse --nth=1 --color=fg:dim,nth:regular" \ | ||
| $FZF_COMPLETION_OPTS $argv[2..-1] --accept-nth=1) | ||
| set result (complete -C "$argv[1]" | eval (__fzfcmd)) | ||
lalvarezt marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| end | ||
| and commandline -rt -- (string join ' ' -- $result)' ' | ||
| commandline -f repaint | ||
| end | ||
|
|
||
| # Generic path completion | ||
| function __fzf_generic_path_completion | ||
| set -l parsed (__fzf_parse_commandline) | ||
| set -lx dir $parsed[1] | ||
| set -l fzf_query $parsed[2] | ||
| set -l opt_prefix $parsed[3] | ||
| set -l compgen $argv[1] | ||
| set -l tail " " | ||
|
|
||
| # Set fzf options | ||
| set -lx -- FZF_DEFAULT_OPTS (__fzf_defaults "--reverse --scheme=path" "$FZF_COMPLETION_OPTS --print0") | ||
| set -lx FZF_DEFAULT_COMMAND | ||
| set -lx FZF_DEFAULT_OPTS_FILE | ||
|
|
||
| if string match -q -- '*dir*' $compgen | ||
| set tail "" | ||
| set -a -- FZF_DEFAULT_OPTS "--walker=dir,follow $FZF_COMPLETION_DIR_OPTS" | ||
| else if string match -q -- '*file*' $compgen | ||
| set -a -- FZF_DEFAULT_OPTS "-m --walker=file,follow,hidden $FZF_COMPLETION_FILE_OPTS" | ||
| else | ||
| set -a -- FZF_DEFAULT_OPTS "-m --walker=file,dir,follow,hidden $FZF_COMPLETION_PATH_OPTS" | ||
| end | ||
|
|
||
| # Run fzf | ||
| set -l result | ||
| if functions -q "$compgen" | ||
| set result (eval $compgen $dir | eval (__fzfcmd) --query=$fzf_query | string split0) | ||
| else | ||
| set result (eval (__fzfcmd) --walker-root=$dir --query=$fzf_query | string split0) | ||
| end | ||
| and commandline -rt -- (string join -- ' ' $opt_prefix(string escape -n -- $result))$tail | ||
|
|
||
| commandline -f repaint | ||
| end | ||
|
|
||
| # Kill completion (process selection) | ||
| function _fzf_complete_kill | ||
| set -lx FZF_DEFAULT_OPTS (__fzf_defaults "--reverse" "$FZF_COMPLETION_OPTS") | ||
| set -lx FZF_DEFAULT_OPTS_FILE | ||
|
|
||
| set -l result (begin | ||
| command ps -eo user,pid,ppid,start,time,command 2>/dev/null | ||
| or command ps -eo user,pid,ppid,time,args 2>/dev/null # BusyBox | ||
| or command ps --everyone --full --windows 2>/dev/null # Cygwin | ||
| end | eval (__fzfcmd) --accept-nth=2 -m --header-lines=1 --no-preview --wrap --query=$argv[1]) | ||
| and commandline -rt -- (string join ' ' -- $result)" " | ||
| commandline -f repaint | ||
| end | ||
|
|
||
| # Main completion function | ||
| function fzf-completion | ||
| set -q FZF_COMPLETION_TRIGGER | ||
| or set -l FZF_COMPLETION_TRIGGER '**' | ||
|
|
||
| # Set variables containing the major and minor fish version numbers, using | ||
| # a method compatible with all supported fish versions. | ||
| set -l -- fish_major (string match -r -- '^\d+' $version) | ||
| set -l -- fish_minor (string match -r -- '^\d+\.(\d+)' $version)[2] | ||
|
|
||
| # Get tokens - use version-appropriate flags | ||
| set -l tokens | ||
| if test $fish_major -ge 4 | ||
| set tokens (commandline -xpc) | ||
| else | ||
| set tokens (commandline -opc) | ||
| end | ||
|
|
||
| set -l -- current_token (commandline -t) | ||
| set -l -- cmd_name $tokens[1] | ||
|
|
||
| set -l -- has_trigger false | ||
| string match -qr -- (string escape --style regex -- $FZF_COMPLETION_TRIGGER)'$' $current_token | ||
| and set has_trigger true | ||
|
|
||
| # Strip trigger from commandline before parsing | ||
| if $has_trigger; and test -n "$FZF_COMPLETION_TRIGGER" -a -n "$current_token" | ||
| set -- current_token (string sub -e -(string length -- "$FZF_COMPLETION_TRIGGER") -- $current_token) | ||
| commandline -rt -- $current_token | ||
| end | ||
|
|
||
| if not $has_trigger | ||
| commandline -f complete | ||
| return | ||
| else if test -z "$tokens" | ||
| __fzf_complete_native "" --query=$current_token | ||
| return | ||
| end | ||
|
|
||
| set -l disable_opt_comp false | ||
| if not test "$fish_major" -eq 3 -a "$fish_minor" -lt 3 | ||
| string match -qe -- ' -- ' (string sub -l (commandline -Cp) -- (commandline -p)) | ||
| and set disable_opt_comp true | ||
| end | ||
|
|
||
| if not $disable_opt_comp | ||
| # Not using the --groups-only option of string-match, because it is | ||
| # not available on fish versions older that 3.4.0 | ||
| set -l -- cmd_opt (string match -r -- '^(-{1,2})([\w.,:+-]*)$' $current_token) | ||
| if test -n "$cmd_opt[2]" -a \( "$cmd_opt[2]" = -- -o (string length -- "$cmd_opt[3]") -ne 1 \) | ||
| __fzf_complete_native "$cmd_name $cmd_opt[2]" --query=$cmd_opt[3] --multi | ||
| return | ||
| end | ||
| end | ||
|
|
||
| # Directory commands | ||
| set -q FZF_COMPLETION_DIR_COMMANDS | ||
| or set -l FZF_COMPLETION_DIR_COMMANDS cd pushd rmdir | ||
|
|
||
| # File-only commands | ||
| set -q FZF_COMPLETION_FILE_COMMANDS | ||
| or set -l FZF_COMPLETION_FILE_COMMANDS cat head tail less more | ||
|
|
||
| # Native completion commands | ||
| set -q FZF_COMPLETION_NATIVE_COMMANDS | ||
| or set -l FZF_COMPLETION_NATIVE_COMMANDS ssh telnet | ||
|
|
||
| # Native completion commands (multi-selection) | ||
| set -q FZF_COMPLETION_NATIVE_COMMANDS_MULTI | ||
| or set -l FZF_COMPLETION_NATIVE_COMMANDS_MULTI set functions type | ||
|
|
||
| # Route to appropriate completion function | ||
| if functions -q _fzf_complete_$cmd_name | ||
| _fzf_complete_$cmd_name "$fzf_query" "$cmd_name" | ||
| else if contains -- "$cmd_name" $FZF_COMPLETION_NATIVE_COMMANDS $FZF_COMPLETION_NATIVE_COMMANDS_MULTI | ||
| set -l -- fzf_opt --query=(commandline -t | string escape) | ||
| contains -- "$cmd_name" $FZF_COMPLETION_NATIVE_COMMANDS_MULTI | ||
| and set -a -- fzf_opt --multi | ||
| __fzf_complete_native "$cmd_name " $fzf_opt | ||
| else if contains -- "$cmd_name" $FZF_COMPLETION_DIR_COMMANDS | ||
| __fzf_generic_path_completion _fzf_compgen_dir | ||
| else if contains -- "$cmd_name" $FZF_COMPLETION_FILE_COMMANDS | ||
| __fzf_generic_path_completion _fzf_compgen_file | ||
| else | ||
| __fzf_generic_path_completion _fzf_compgen_path | ||
| end | ||
| end | ||
|
|
||
| # Bind tab to fzf-completion | ||
| bind \t fzf-completion | ||
| bind -M insert \t fzf-completion | ||
| end | ||
|
|
||
| # Run setup | ||
| fzf_completion_setup | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| # Unset fzf variables | ||
| set -e FZF_DEFAULT_COMMAND FZF_DEFAULT_OPTS FZF_DEFAULT_OPTS_FILE FZF_TMUX FZF_TMUX_OPTS | ||
| set -e FZF_CTRL_T_COMMAND FZF_CTRL_T_OPTS FZF_ALT_C_COMMAND FZF_ALT_C_OPTS FZF_CTRL_R_OPTS | ||
| set -e FZF_API_KEY | ||
| # Unset completion-specific variables | ||
| set -e FZF_COMPLETION_TRIGGER FZF_COMPLETION_OPTS | ||
| set -e FZF_COMPLETION_PATH_OPTS FZF_COMPLETION_DIR_OPTS FZF_COMPLETION_FILE_OPTS | ||
| set -e FZF_COMPLETION_DIR_COMMANDS FZF_COMPLETION_FILE_COMMANDS FZF_COMPLETION_NATIVE_COMMANDS | ||
| set -e FZF_COMPLETION_NATIVE_MODE | ||
|
|
||
| set -gx FZF_DEFAULT_OPTS "--no-scrollbar --pointer '>' --marker '>'" | ||
| set -gx FZF_COMPLETION_TRIGGER '++' | ||
| set -gx fish_history fzf_test | ||
|
|
||
| # Add fzf to PATH | ||
| fish_add_path <%= BASE %>/bin | ||
|
|
||
| # Source key bindings and completion | ||
| source "<%= BASE %>/shell/key-bindings.fish" | ||
| source "<%= BASE %>/shell/completion.fish" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.