summaryrefslogtreecommitdiffstats
path: root/shell
diff options
context:
space:
mode:
authorJack Bates <jack@nottheoilrig.com>2020-02-23 08:17:38 -0700
committerGitHub <noreply@github.com>2020-02-24 00:17:38 +0900
commit5cae8ea733e8663eae96480b5e6d4c94afcdb3bd (patch)
tree423143ea043064de216a13591253662a702a5788 /shell
parent1ccd8f6a647a31f8cb1d683d25d9f21ab28b11cc (diff)
[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 <junegunn.c@gmail.com>
Diffstat (limited to 'shell')
-rw-r--r--shell/key-bindings.bash17
1 files changed, 6 insertions, 11 deletions
diff --git a/shell/key-bindings.bash b/shell/key-bindings.bash
index d41f0be1..742a83a4 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"'