diff --git a/functions/_fzf_configure_bindings_help.fish b/functions/_fzf_configure_bindings_help.fish index ecfe68e..3bb2f65 100644 --- a/functions/_fzf_configure_bindings_help.fish +++ b/functions/_fzf_configure_bindings_help.fish @@ -10,13 +10,14 @@ DESCRIPTION By default, commands are bound to a mnemonic key sequence, shown below. Each command's binding can be configured using a namesake corresponding option: - COMMAND | DEFAULT KEY SEQUENCE | CORRESPONDING OPTION - Search Directory | Ctrl+Alt+F (F for file) | --directory - Search Git Log | Ctrl+Alt+L (L for log) | --git_log - Search Git Status | Ctrl+Alt+S (S for status) | --git_status - Search History | Ctrl+R (R for reverse) | --history - Search Processes | Ctrl+Alt+P (P for process) | --processes - Search Variables | Ctrl+V (V for variable) | --variables + COMMAND | DEFAULT KEY SEQUENCE | CORRESPONDING OPTION + Search Completions | Ctrl+Alt+T (T for tab completion) | --completions + Search Directory | Ctrl+Alt+F (F for file) | --directory + Search Git Log | Ctrl+Alt+L (L for log) | --git_log + Search Git Status | Ctrl+Alt+S (S for status) | --git_status + Search History | Ctrl+R (R for reverse) | --history + Search Processes | Ctrl+Alt+P (P for process) | --processes + Search Variables | Ctrl+V (V for variable) | --variables Override a command's binding by specifying its corresponding option with the desired key sequence. Disable a command's binding by specifying its corresponding option with no value. @@ -35,7 +36,7 @@ EXAMPLES Default bindings but disable Search History \$ fzf_configure_bindings --history= An agglomeration of different options - \$ fzf_configure_bindings --git_status=\cg --history=\ch --variables= --processes= + \$ fzf_configure_bindings --git_status=\cg --completions=\t --variables= --processes= SEE Also To learn more about fish key bindings, see bind(1) and fish_key_reader(1). diff --git a/functions/_fzf_search_completions.fish b/functions/_fzf_search_completions.fish new file mode 100644 index 0000000..6b571d7 --- /dev/null +++ b/functions/_fzf_search_completions.fish @@ -0,0 +1,26 @@ +# External limitations: +# - fish-shell/fish-shell#9577: folders ending in '=' break fish's internal path completion +# (It thinks that it has to complete from / because `a_folder=/` looks like an argument to fish. +# - fish cannot give reliable context information on completions. Knowing whether a completion +# is a file or argument can only be determined via a heuristic. +function _fzf_search_completions --description "Search the completions for the current command line. Replace the current token with the selected completions." + set -l selected_completions ( + complete --do-complete (commandline --cut-at-cursor) | + string join0 | + _fzf_wrapper \ + --read0 \ + --print0 \ + --ansi \ + --multi \ + $fzf_completions_opts \ + | string split0 + ) + if test $status -eq 0 + # Strip away description + for completion in $selected_completions + set --append results (string split --fields 1 --max 1 --right \t -- $completion) + end + commandline --current-token --replace -- (string escape -- $results | string join ' ') + end + commandline --function repaint +end diff --git a/functions/fzf_configure_bindings.fish b/functions/fzf_configure_bindings.fish index 4b4e7a2..270b649 100644 --- a/functions/fzf_configure_bindings.fish +++ b/functions/fzf_configure_bindings.fish @@ -4,7 +4,7 @@ function fzf_configure_bindings --description "Installs the default key bindings # no need to install bindings if not in interactive mode or running tests status is-interactive || test "$CI" = true; or return - set -f options_spec h/help 'directory=?' 'git_log=?' 'git_status=?' 'history=?' 'processes=?' 'variables=?' + set -f options_spec h/help 'completions=?' 'directory=?' 'git_log=?' 'git_status=?' 'history=?' 'processes=?' 'variables=?' argparse --max-args=0 --ignore-unknown $options_spec -- $argv 2>/dev/null if test $status -ne 0 echo "Invalid option or a positional argument was provided." >&2 @@ -15,14 +15,16 @@ function fzf_configure_bindings --description "Installs the default key bindings return else # Initialize with default key sequences and then override or disable them based on flags - # index 1 = directory, 2 = git_log, 3 = git_status, 4 = history, 5 = processes, 6 = variables - set -f key_sequences \e\cf \e\cl \e\cs \cr \e\cp \cv # \c = control, \e = escape - set --query _flag_directory && set key_sequences[1] "$_flag_directory" - set --query _flag_git_log && set key_sequences[2] "$_flag_git_log" - set --query _flag_git_status && set key_sequences[3] "$_flag_git_status" - set --query _flag_history && set key_sequences[4] "$_flag_history" - set --query _flag_processes && set key_sequences[5] "$_flag_processes" - set --query _flag_variables && set key_sequences[6] "$_flag_variables" + # arrange the key sequences in alphabetical order of the Search Command name + set -f key_sequences \e\ct \e\cf \e\cl \e\cs \cr \e\cp \cv # \c = control, \e = escape + + set --query _flag_completions && set key_sequences[1] "$_flag_completions" + set --query _flag_directory && set key_sequences[2] "$_flag_directory" + set --query _flag_git_log && set key_sequences[3] "$_flag_git_log" + set --query _flag_git_status && set key_sequences[4] "$_flag_git_status" + set --query _flag_history && set key_sequences[5] "$_flag_history" + set --query _flag_processes && set key_sequences[6] "$_flag_processes" + set --query _flag_variables && set key_sequences[7] "$_flag_variables" # If fzf bindings already exists, uninstall it first for a clean slate if functions --query _fzf_uninstall_bindings @@ -30,12 +32,13 @@ function fzf_configure_bindings --description "Installs the default key bindings end for mode in default insert - test -n $key_sequences[1] && bind --mode $mode $key_sequences[1] _fzf_search_directory - test -n $key_sequences[2] && bind --mode $mode $key_sequences[2] _fzf_search_git_log - test -n $key_sequences[3] && bind --mode $mode $key_sequences[3] _fzf_search_git_status - test -n $key_sequences[4] && bind --mode $mode $key_sequences[4] _fzf_search_history - test -n $key_sequences[5] && bind --mode $mode $key_sequences[5] _fzf_search_processes - test -n $key_sequences[6] && bind --mode $mode $key_sequences[6] "$_fzf_search_vars_command" + test -n $key_sequences[1] && bind --mode $mode $key_sequences[1] _fzf_search_completions + test -n $key_sequences[2] && bind --mode $mode $key_sequences[2] _fzf_search_directory + test -n $key_sequences[3] && bind --mode $mode $key_sequences[3] _fzf_search_git_log + test -n $key_sequences[4] && bind --mode $mode $key_sequences[4] _fzf_search_git_status + test -n $key_sequences[5] && bind --mode $mode $key_sequences[5] _fzf_search_history + test -n $key_sequences[6] && bind --mode $mode $key_sequences[6] _fzf_search_processes + test -n $key_sequences[7] && bind --mode $mode $key_sequences[7] "$_fzf_search_vars_command" end function _fzf_uninstall_bindings --inherit-variable key_sequences