From 5cae8ea733e8663eae96480b5e6d4c94afcdb3bd Mon Sep 17 00:00:00 2001 From: Jack Bates Date: Sun, 23 Feb 2020 08:17:38 -0700 Subject: [PATCH] [bash] Multiline C-r without histexpand (#1837) Close #1370 Parses the history list, converts it to a NUL-delimited list of possibly multiline entries. Adds the fzf --read0 option. Works with and without histexpand enabled. Co-authored-by: Junegunn Choi --- shell/key-bindings.bash | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/shell/key-bindings.bash b/shell/key-bindings.bash index d41f0be..742a83a 100644 --- a/shell/key-bindings.bash +++ b/shell/key-bindings.bash @@ -53,21 +53,16 @@ __fzf_cd__() { __fzf_history__() ( local line - shopt -u nocaseglob nocasematch line=$( - HISTTIMEFORMAT= builtin history | - FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} $FZF_DEFAULT_OPTS --tac --sync -n2..,.. --tiebreak=index --bind=ctrl-r:toggle-sort $FZF_CTRL_R_OPTS +m" $(__fzfcmd) | - command grep '^ *[0-9]') && - if [[ $- =~ H ]]; then - sed 's/^ *\([0-9]*\)\** .*/!\1/' <<< "$line" - else - sed 's/^ *\([0-9]*\)\** *//' <<< "$line" - fi + builtin fc -lnr -2147483648 | + perl -p -l0 -e 'BEGIN { getc; $/ = "\n\t" } s/^[ *]//; $_ = '"$1"' - $. . "\t$_"' | + FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} $FZF_DEFAULT_OPTS --tiebreak=index --bind=ctrl-r:toggle-sort $FZF_CTRL_R_OPTS +m --read0" $(__fzfcmd) + ) + echo "${line#*$'\t'}" ) # Required to refresh the prompt after fzf bind -m emacs-standard '"\er": redraw-current-line' -bind -m emacs-standard '"\e^": history-expand-line' # CTRL-T - Paste the selected file path into the command line if [ $BASH_VERSINFO -gt 3 ]; then @@ -79,7 +74,7 @@ else fi # CTRL-R - Paste the selected command from history into the command line -bind -m emacs-standard '"\C-r": "\C-e \C-u\C-y\ey\C-u`__fzf_history__`\e\C-e\er\e^"' +bind -m emacs-standard '"\C-r": "\C-e \C-u\C-y\ey\C-u__fzf_history__ $HISTCMD\e\C-e`"\C-a"`\C-e\e\C-e\er"' # ALT-C - cd into the selected directory bind -m emacs-standard '"\ec": " \C-b\C-k \C-u`__fzf_cd__`\e\C-e\er\C-m\C-y\C-h\e \C-y\ey\C-x\C-x\C-d"'