@@ -51,47 +51,56 @@ __fzf_cd__() {
51
51
dir=$( eval " $cmd " | FZF_DEFAULT_OPTS=" --height ${FZF_TMUX_HEIGHT:- 40% } --reverse $FZF_DEFAULT_OPTS $FZF_ALT_C_OPTS " $( __fzfcmd) +m) && printf ' cd %q' " $dir "
52
52
}
53
53
54
- __fzf_history__ () (
55
- local line
56
- line =$(
54
+ __fzf_history__ () {
55
+ local output
56
+ output =$(
57
57
builtin fc -lnr -2147483648 |
58
- perl -p -l0 -e ' BEGIN { getc; $/ = "\n\t" } s/^[ *]//; $_ = ' " $1 " ' - $. . "\t$_"' |
59
- 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)
60
- )
61
- echo " ${line#* $' \t ' } "
62
- )
58
+ last_hist=$( HISTTIMEFORMAT=' ' builtin history 1) perl -p -l0 -e ' BEGIN { getc; $/ = "\n\t"; $HISTCMD = $ENV{last_hist} + 1 } s/^[ *]//; $_ = $HISTCMD - $. . "\t$_"' |
59
+ FZF_DEFAULT_OPTS=" --height ${FZF_TMUX_HEIGHT:- 40% } $FZF_DEFAULT_OPTS --tiebreak=index --bind=ctrl-r:toggle-sort $FZF_CTRL_R_OPTS +m --query $( printf %q " $READLINE_LINE " ) --read0" $( __fzfcmd)
60
+ ) || return
61
+ READLINE_LINE=${output#* $' \t ' }
62
+ if [ -z " $READLINE_POINT " ]; then
63
+ echo " $READLINE_LINE "
64
+ else
65
+ READLINE_POINT=0x7fffffff
66
+ fi
67
+ }
63
68
64
69
# Required to refresh the prompt after fzf
65
70
bind -m emacs-standard ' "\er": redraw-current-line'
66
71
67
- # CTRL-T - Paste the selected file path into the command line
68
- if [ $BASH_VERSINFO -gt 3 ]; then
69
- bind -m emacs-standard -x ' "\C-t": "fzf-file-widget"'
70
- elif __fzf_use_tmux__; then
71
- bind -m emacs-standard ' "\C-t": " \C-b\C-k \C-u`__fzf_select_tmux__`\e\C-e\C-a\C-y\C-h\C-e\e \C-y\ey\C-x\C-x\C-f"'
72
- else
73
- bind -m emacs-standard ' "\C-t": " \C-b\C-k \C-u`__fzf_select__`\e\C-e\er\C-a\C-y\C-h\C-e\e \C-y\ey\C-x\C-x\C-f"'
74
- fi
75
-
76
- # CTRL-R - Paste the selected command from history into the command line
77
- 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"'
78
-
79
- # ALT-C - cd into the selected directory
80
- 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"'
81
-
82
72
bind -m vi-command ' "\C-z": emacs-editing-mode'
83
73
bind -m vi-insert ' "\C-z": emacs-editing-mode'
84
74
bind -m emacs-standard ' "\C-z": vi-editing-mode'
85
75
86
- # CTRL-T - Paste the selected file path into the command line
87
- bind -m vi-command ' "\C-t": "\C-z\C-t\C-z"'
88
- bind -m vi-insert ' "\C-t": "\C-z\C-t\C-z"'
76
+ if [ " ${BASH_VERSINFO[0]} " -lt 4 ]; then
77
+ # CTRL-T - Paste the selected file path into the command line
78
+ if __fzf_use_tmux__; then
79
+ bind -m emacs-standard ' "\C-t": " \C-b\C-k \C-u`__fzf_select_tmux__`\e\C-e\C-a\C-y\C-h\C-e\e \C-y\ey\C-x\C-x\C-f"'
80
+ else
81
+ bind -m emacs-standard ' "\C-t": " \C-b\C-k \C-u`__fzf_select__`\e\C-e\er\C-a\C-y\C-h\C-e\e \C-y\ey\C-x\C-x\C-f"'
82
+ fi
83
+ bind -m vi-command ' "\C-t": "\C-z\C-t\C-z"'
84
+ bind -m vi-insert ' "\C-t": "\C-z\C-t\C-z"'
89
85
90
- # CTRL-R - Paste the selected command from history into the command line
91
- bind -m vi-command ' "\C-r": "\C-z\C-r\C-z"'
92
- bind -m vi-insert ' "\C-r": "\C-z\C-r\C-z"'
86
+ # CTRL-R - Paste the selected command from history into the command line
87
+ bind -m emacs-standard ' "\C-r": "\C-e \C-u\C-y\ey\C-u"$(__fzf_history__)"\e\C-e\er"'
88
+ bind -m vi-command ' "\C-r": "\C-z\C-r\C-z"'
89
+ bind -m vi-insert ' "\C-r": "\C-z\C-r\C-z"'
90
+ else
91
+ # CTRL-T - Paste the selected file path into the command line
92
+ bind -m emacs-standard -x ' "\C-t": fzf-file-widget'
93
+ bind -m vi-command -x ' "\C-t": fzf-file-widget'
94
+ bind -m vi-insert -x ' "\C-t": fzf-file-widget'
95
+
96
+ # CTRL-R - Paste the selected command from history into the command line
97
+ bind -m emacs-standard -x ' "\C-r": __fzf_history__'
98
+ bind -m vi-command -x ' "\C-r": __fzf_history__'
99
+ bind -m vi-insert -x ' "\C-r": __fzf_history__'
100
+ fi
93
101
94
102
# ALT-C - cd into the selected directory
103
+ 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"'
95
104
bind -m vi-command ' "\ec": "\C-z\ec\C-z"'
96
105
bind -m vi-insert ' "\ec": "\C-z\ec\C-z"'
97
106
0 commit comments