From c9974efc1275c27d5ee065afbd1610de55fae108 Mon Sep 17 00:00:00 2001 From: Jorge Bucaran Date: Wed, 17 Oct 2018 14:42:52 +0900 Subject: [PATCH] feat: add user key bindings autoloading for legacy fish Packages add key bindings via configuration snippets. As it turns out, configuration snippets are not available in legacy fish and only fish 3.0 or newer can use the bind builtin on shell startup. To support packages that add key bindings in legacy fish, we make a copy of the user's fish_user_key_bindings function (if there it exists) and create a new one that when called, will source every *_key_bindings.fish inside \$fisher_path/conf.d and finally run our copy of the user's fish_user_key_bindings, if it exists, to preserve any user defined key bindings. To be able to run code on shell startup we create a fisher.fish file inside \$fisher_path/conf.d if running an older version of fish. When the user upgrades to a supported fish version, we'll automatically remove this file. --- fisher.fish | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/fisher.fish b/fisher.fish index a689018..c96714e 100644 --- a/fisher.fish +++ b/fisher.fish @@ -35,9 +35,21 @@ function fisher -a cmd -d "fish package manager" _fisher_self_complete end + if test -e "$fisher_path/conf.d/fisher.fish" + command rm -f $fisher_path/conf.d/fisher.fish + end + + switch "$version" + case \*-\* + case 2\* + echo "fisher copy-user-key-bindings" > $fisher_path/conf.d/fisher.fish + end + switch "$cmd" case self-complete _fisher_self_complete + case copy-user-key-bindings + _fisher_copy_user_key_bindings case ls _fisher_ls | command sed "s|$HOME|~|" case -v {,--}version @@ -79,6 +91,20 @@ function _fisher_self_complete end end +function _fisher_copy_user_key_bindings + if functions -q fish_user_key_bindings + functions -c fish_user_key_bindings fish_user_key_bindings_copy + end + function fish_user_key_bindings + for file in $fisher_path/conf.d/*_key_bindings.fish + source $file >/dev/null 2>/dev/null + end + if functions -q fish_user_key_bindings_copy + fish_user_key_bindings_copy + end + end +end + function _fisher_ls set -l pkgs $fisher_config/*/*/* for pkg in $pkgs @@ -135,7 +161,7 @@ end function _fisher_self_uninstall set -l current_pkgs $fisher_config/*/*/* - for path in $fisher_cache (_fisher_pkg_remove_all $current_pkgs) $fisher_config $fisher_path/{functions,completions}/fisher.fish $fish_config/fishfile + for path in $fisher_cache (_fisher_pkg_remove_all $current_pkgs) $fisher_config $fisher_path/{functions,completions,conf.d}/fisher.fish $fish_config/fishfile echo "removing $path" command rm -rf $path 2>/dev/null end | command sed "s|$HOME|~|" >&2