flocon/dot_config/fish/functions/fzf_configure_bindings.fish
Anthony Rodriguez dc7ee4d021 Add .config/fish/functions/_fzf_configure_bindings_help.fish
Add .config/fish/functions/_fzf_extract_var_info.fish
Add .config/fish/functions/_fzf_preview_changed_file.fish
Add .config/fish/functions/_fzf_preview_file.fish
Add .config/fish/functions/_fzf_report_diff_type.fish
Add .config/fish/functions/_fzf_report_file_type.fish
Add .config/fish/functions/_fzf_search_directory.fish
Add .config/fish/functions/_fzf_search_git_log.fish
Add .config/fish/functions/_fzf_search_git_status.fish
Add .config/fish/functions/_fzf_search_history.fish
Add .config/fish/functions/_fzf_search_processes.fish
Add .config/fish/functions/_fzf_search_variables.fish
Add .config/fish/functions/_fzf_wrapper.fish
Add .config/fish/functions/_nvm_index_update.fish
Add .config/fish/functions/_nvm_list.fish
Add .config/fish/functions/_nvm_version_activate.fish
Add .config/fish/functions/_nvm_version_deactivate.fish
Add .config/fish/functions/fish_greeting.fish
Add .config/fish/functions/fish_mode_prompt.fish
Add .config/fish/functions/fish_title.fish
Add .config/fish/functions/fzf_configure_bindings.fish
Add .config/fish/functions/nvm.fish
2024-06-07 11:48:47 +02:00

46 lines
2.6 KiB
Fish

# Always installs bindings for insert and default mode for simplicity and b/c it has almost no side-effect
# https://gitter.im/fish-shell/fish-shell?at=60a55915ee77a74d685fa6b1
function fzf_configure_bindings --description "Installs the default key bindings for fzf.fish with user overrides passed as options."
# 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=?'
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
_fzf_configure_bindings_help
return 22
else if set --query _flag_help
_fzf_configure_bindings_help
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"
# 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"
end
function _fzf_uninstall_bindings --inherit-variable key_sequences
bind --erase -- $key_sequences
bind --erase --mode insert -- $key_sequences
end
end
end