akinomyoga / blesh-contrib

Source of settings for Bash Line Editor https://github.com/akinomyoga/ble.sh (for ble-0.4+)
BSD 3-Clause "New" or "Revised" License
36 stars 10 forks source link

Allow disabling some fzf key bindings #8

Closed pdecat closed 2 years ago

pdecat commented 2 years ago

I switched from fzf to https://github.com/ellie/atuin for my shell history needs with the Ctrl-R binding, but still use the other Alt-C and Ctrl-T fzf bindings.

It would be awesome to be able to disable some binding by ble.sh configuration.

For now, I just remove the lines related to history:

diff --git a/fzf-key-bindings.bash b/fzf-key-bindings.bash
index 9ef2774..11e8fad 100644
--- a/fzf-key-bindings.bash
+++ b/fzf-key-bindings.bash
@@ -22,18 +22,6 @@ ble-bind -m emacs   -x C-t fzf-file-widget
 ble-bind -m vi_imap -x C-t fzf-file-widget
 ble-bind -m vi_nmap -s C-t 'i\C-t'

-# CTRL-R - Paste the selected command from history into the command line
-ble-bind -m emacs   -x C-r fzf-history-widget
-ble-bind -m vi_imap -x C-r fzf-history-widget
-ble-bind -m vi_nmap -s C-r 'i\C-r'
-function fzf-history-widget {
-  READLINE_LINE=$(history -p "$(__fzf_history__)")
-  READLINE_POINT=${#READLINE_LINE}
-}
-((_ble_bash>=40000)) &&
-  ble/contrib/fzf-key-bindings/is-fzf-above-7c447bbd &&
-  function fzf-history-widget { __fzf_history__; }
-
 # ALT-C - cd into the selected directory
 ble-bind -m emacs   -c M-c 'eval "$(__fzf_cd__)"'
 ble-bind -m vi_imap -c M-c 'eval "$(__fzf_cd__)"'
@@ -41,7 +29,6 @@ ble-bind -m vi_nmap -c M-c 'eval "$(__fzf_cd__)"'

 # patch fzf functions
 ble/function#advice around fzf-file-widget ble/contrib/fzf-key-bindings.advice
-ble/function#advice around __fzf_history__ ble/contrib/fzf-key-bindings.advice
 ble/function#advice around __fzf_cd__      ble/contrib/fzf-key-bindings.advice
 function ble/contrib/fzf-key-bindings.advice {
   if [[ ! $_ble_attached ]]; then
akinomyoga commented 2 years ago

Thank you for the suggestion.

For now, I just remove the lines related to history:

diff --git a/fzf-key-bindings.bash b/fzf-key-bindings.bash
index 9ef2774..11e8fad 100644
--- a/fzf-key-bindings.bash
+++ b/fzf-key-bindings.bash
@@ -22,18 +22,6 @@ ble-bind -m emacs   -x C-t fzf-file-widget
 ble-bind -m vi_imap -x C-t fzf-file-widget
 ble-bind -m vi_nmap -s C-t 'i\C-t'

-# CTRL-R - Paste the selected command from history into the command line
-ble-bind -m emacs   -x C-r fzf-history-widget
-ble-bind -m vi_imap -x C-r fzf-history-widget
-ble-bind -m vi_nmap -s C-r 'i\C-r'
-function fzf-history-widget {
-  READLINE_LINE=$(history -p "$(__fzf_history__)")
-  READLINE_POINT=${#READLINE_LINE}
-}
-((_ble_bash>=40000)) &&
-  ble/contrib/fzf-key-bindings/is-fzf-above-7c447bbd &&
-  function fzf-history-widget { __fzf_history__; }
-
 # ALT-C - cd into the selected directory
 ble-bind -m emacs   -c M-c 'eval "$(__fzf_cd__)"'
 ble-bind -m vi_imap -c M-c 'eval "$(__fzf_cd__)"'
@@ -41,7 +29,6 @@ ble-bind -m vi_nmap -c M-c 'eval "$(__fzf_cd__)"'

 # patch fzf functions
 ble/function#advice around fzf-file-widget ble/contrib/fzf-key-bindings.advice
-ble/function#advice around __fzf_history__ ble/contrib/fzf-key-bindings.advice
 ble/function#advice around __fzf_cd__      ble/contrib/fzf-key-bindings.advice
 function ble/contrib/fzf-key-bindings.advice {
   if [[ ! $_ble_attached ]]; then

Well, the above is actually what I expect each user to do. If I would add one thing, to avoid conflicts on future updates, I'd recommend you to copy contrib/fzf-key-bindings.bash to another file (e.g. contrib/my-fzf-key-bindings.bash), edit the copy, and import it as e.g. ble-import -d contrib/my-fzf-key-bindings.

The file contrib/fzf-key-bindings just adjusts the keybindings defined in shell/key-bindings.bash of the upstream fzf. There is no plan to make it behave differently from the upstream shell/key-bindings.bash. If the upstream is going to support some mechanism to disable the selected keybindings, I will follow it. Maybe you could first ask the upstream for configurable keybindings. I found some related issues in the upstream repository:

pdecat commented 2 years ago

Ok, good for me then :) Thanks for the prompt response!