From 392da53f5380907fdc7c21f398612be82f7dc3e0 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Mon, 13 Jul 2015 00:22:13 +0900 Subject: [PATCH] [bash] Make CTRL-R work when histexpand is unset (#286) Note that it still can't handle properly multi-line commands. Thanks to @jpcirrus for the bug report and the fix. --- shell/key-bindings.bash | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/shell/key-bindings.bash b/shell/key-bindings.bash index c04dc44..0bfd50d 100644 --- a/shell/key-bindings.bash +++ b/shell/key-bindings.bash @@ -34,13 +34,19 @@ __fzf_cd__() { -o -type d -print 2> /dev/null | sed 1d | cut -b3- | $(__fzfcmd) +m) && printf 'cd %q' "$dir" } -__fzf_history__() { +__fzf_history__() ( local line + shopt -u nocaseglob nocasematch line=$( HISTTIMEFORMAT= history | $(__fzfcmd) +s --tac +m -n2..,.. --tiebreak=index --toggle-sort=ctrl-r | - \grep '^ *[0-9]') && sed 's/ *\([0-9]*\)\** .*/!\1/' <<< "$line" -} + \grep '^ *[0-9]') && + if [[ $- =~ H ]]; then + sed 's/^ *\([0-9]*\)\** .*/!\1/' <<< "$line" + else + sed 's/^ *\([0-9]*\)\** *//' <<< "$line" + fi +) __use_tmux=0 [ -n "$TMUX_PANE" -a ${FZF_TMUX:-1} -ne 0 -a ${LINES:-40} -gt 15 ] && __use_tmux=1