diff --git a/conf.d/fzf.fish b/conf.d/fzf.fish index 56a263fb..80e192df 100644 --- a/conf.d/fzf.fish +++ b/conf.d/fzf.fish @@ -2,7 +2,7 @@ # them before even executing __fzf_search_shell_variables. We use psub to store the # variables' info in temporary files and pass in the filenames as arguments. # # This variable is global so that it can be referenced by fzf_install_bindings and in tests -set --global __fzf_search_vars_command '__fzf_search_shell_variables (set --show | psub) (set --names | psub)' +set --global _fzf_search_vars_command '__fzf_search_shell_variables (set --show | psub) (set --names | psub)' # Install some safe and memorable key bindings by default fzf_conflictless_mnemonic_keymap @@ -22,8 +22,8 @@ end # Doesn't erase FZF_DEFAULT_OPTS because too hard to tell if it was set by the user or by this plugin # Doesn't erase autoloaded __fzf_* functions because they will not be easily accessible once key bindings are erased function _fzf_uninstall --on-event fzf_uninstall - set --erase __fzf_search_vars_command - fzf_uninstall_keymap + set --erase _fzf_search_vars_command + _fzf_uninstall_keymap functions --erase _fzf_uninstall _fzf_migration_message functions --erase fzf_uninstall_keymap fzf_install_keymap fzf_conflictless_mnemonic_keymap fzf_simple_mnemonic_keymap diff --git a/functions/__fzf_install_keymap_help.fish b/functions/_fzf_install_keymap_help.fish similarity index 96% rename from functions/__fzf_install_keymap_help.fish rename to functions/_fzf_install_keymap_help.fish index 8780be9f..78244fe2 100644 --- a/functions/__fzf_install_keymap_help.fish +++ b/functions/_fzf_install_keymap_help.fish @@ -1,4 +1,4 @@ -function __fzf_install_keymap_help +function _fzf_install_keymap_help echo 'fzf_install_keymap - installs a set of key bindings for fzf.fish.' echo 'Usage:' echo ' fzf_install_keymap --searchable_entity=key_sequence...' diff --git a/functions/fzf_install_keymap.fish b/functions/fzf_install_keymap.fish index 80fdc099..7f7a6e2e 100644 --- a/functions/fzf_install_keymap.fish +++ b/functions/fzf_install_keymap.fish @@ -1,43 +1,40 @@ # Supports overriding bindings set by pre-configured keymaps with appended user-specified bindings +# Always installs and uninstalls bindings for insert mode since for simplicity and b/c it has almost no side-effect +# https://gitter.im/fish-shell/fish-shell?at=60a55915ee77a74d685fa6b1 function fzf_install_keymap --description "Install a set of key bindings for fzf.fish's functions using the specified key sequences." if test (count $argv) -eq 0 - __fzf_install_keymap_help + _fzf_install_keymap_help return end set options_spec h/help directory= git_log= git_status= history= variables= argparse --max-args=0 --ignore-unknown $options_spec -- $argv 2>/dev/null if test $status -ne 0 - __fzf_install_keymap_help + _fzf_install_keymap_help return 22 else if set --query _flag_h - __fzf_install_keymap_help + _fzf_install_keymap_help return end # If another keymap already exists, uninstall it first for a clean slate - if functions --query fzf_uninstall_keymap - fzf_uninstall_keymap + if functions --query _fzf_uninstall_keymap + _fzf_uninstall_keymap end + # when no key sequence is provided for an entity, bind gives an error + # and so we ignore all the stderr from these bind commands begin - bind $_flag_directory __fzf_search_current_dir - bind $_flag_git_log __fzf_search_git_log - bind $_flag_git_status __fzf_search_git_status - bind $_flag_history __fzf_search_history - bind $_flag_variables $__fzf_search_vars_command - - # set up the same bindings for insert mode if using insert mode - if contains insert (bind --list-modes) - bind --mode insert $_flag_directory __fzf_search_current_dir - bind --mode insert $_flag_git_log __fzf_search_git_log - bind --mode insert $_flag_git_status __fzf_search_git_status - bind --mode insert $_flag_history __fzf_search_history - bind --mode insert $_flag_variables $__fzf_search_vars_command + for mode in default insert + bind --mode $mode $_flag_directory __fzf_search_current_dir + bind --mode $mode $_flag_git_log __fzf_search_git_log + bind --mode $mode $_flag_git_status __fzf_search_git_status + bind --mode $mode $_flag_history __fzf_search_history + bind --mode $mode $_flag_variables $_fzf_search_vars_command end end 2>/dev/null - function fzf_uninstall_keymap \ + function _fzf_uninstall_keymap \ --inherit-variable _flag_directory \ --inherit-variable _flag_git_log \ --inherit-variable _flag_git_status \ diff --git a/tests/search_shell_variables/$_in_curr_token.fish b/tests/search_shell_variables/$_in_curr_token.fish index dd0e209e..0fa07a46 100644 --- a/tests/search_shell_variables/$_in_curr_token.fish +++ b/tests/search_shell_variables/$_in_curr_token.fish @@ -3,5 +3,5 @@ mock commandline --current-token "echo \\\$variable" mock commandline "--current-token --replace" "echo \$argv" # instead of updating commandline with the result, just output it mock fzf \* "echo selection" -set actual (eval $__fzf_search_vars_command) +set actual (eval $_fzf_search_vars_command) @test "doesn't overwrite \$ when replacing current token with selected variable" "$actual" = "\$selection" diff --git a/tests/search_shell_variables/local_var.fish b/tests/search_shell_variables/local_var.fish index e3379699..ad012a9d 100644 --- a/tests/search_shell_variables/local_var.fish +++ b/tests/search_shell_variables/local_var.fish @@ -2,5 +2,5 @@ set --local a_local_variable set --export --append FZF_DEFAULT_OPTS "--filter=a_local_variable" mock commandline "--current-token --replace" "echo \$argv" # instead of updating commandline with the result, just output it mock commandline \* "" # mock all other commandline executions to do nothing -set actual (eval $__fzf_search_vars_command) +set actual (eval $_fzf_search_vars_command) @test "can find a local variable" "$actual" = a_local_variable