Skip to content
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

[Search Completions] add beta version #313

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions functions/_fzf_configure_bindings_help.fish
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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).
Expand Down
26 changes: 26 additions & 0 deletions functions/_fzf_search_completions.fish
Original file line number Diff line number Diff line change
@@ -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
33 changes: 18 additions & 15 deletions functions/fzf_configure_bindings.fish
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -15,27 +15,30 @@ 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
_fzf_uninstall_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
Expand Down