[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>
This commit is contained in:
Jack Bates 2020-02-23 08:17:38 -07:00 committed by GitHub
parent 1ccd8f6a64
commit 5cae8ea733
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -53,21 +53,16 @@ __fzf_cd__() {
__fzf_history__() ( __fzf_history__() (
local line local line
shopt -u nocaseglob nocasematch
line=$( line=$(
HISTTIMEFORMAT= builtin history | builtin fc -lnr -2147483648 |
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) | perl -p -l0 -e 'BEGIN { getc; $/ = "\n\t" } s/^[ *]//; $_ = '"$1"' - $. . "\t$_"' |
command grep '^ *[0-9]') && 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)
if [[ $- =~ H ]]; then )
sed 's/^ *\([0-9]*\)\** .*/!\1/' <<< "$line" echo "${line#*$'\t'}"
else
sed 's/^ *\([0-9]*\)\** *//' <<< "$line"
fi
) )
# Required to refresh the prompt after fzf # Required to refresh the prompt after fzf
bind -m emacs-standard '"\er": redraw-current-line' 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 # CTRL-T - Paste the selected file path into the command line
if [ $BASH_VERSINFO -gt 3 ]; then if [ $BASH_VERSINFO -gt 3 ]; then
@ -79,7 +74,7 @@ else
fi fi
# CTRL-R - Paste the selected command from history into the command line # 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 # 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"' 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"'