Skip to content

Commit

Permalink
use for loop to dry up key bindings, uninstall_keymap should be private,
Browse files Browse the repository at this point in the history
use single _
  • Loading branch information
PatrickF1 committed Jun 1, 2021
1 parent befa579 commit 3769cb1
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 25 deletions.
6 changes: 3 additions & 3 deletions conf.d/fzf.fish
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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...'
Expand Down
35 changes: 16 additions & 19 deletions functions/fzf_install_keymap.fish
Original file line number Diff line number Diff line change
@@ -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 \
Expand Down
2 changes: 1 addition & 1 deletion tests/search_shell_variables/$_in_curr_token.fish
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion tests/search_shell_variables/local_var.fish
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 3769cb1

Please sign in to comment.