This repository has been archived by the owner on Jun 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhistory-exec.bash
57 lines (50 loc) · 1.8 KB
/
history-exec.bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
__fzf_history__() (
shopt -u nocaseglob nocasematch
edit_key=${FZF_CTRL_R_EDIT_KEY:-enter}
exec_key=${FZF_CTRL_R_EXEC_KEY:-ctrl-x}
if selected=$(
HISTTIMEFORMAT= 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 --expect=$edit_key,$exec_key +m" $(__fzfcmd) |
command grep "^\\($exec_key$\\|$edit_key$\\| *[0-9]\\)")
then
key=${selected%%$'\n'*}
line=${selected#*$'\n'}
result=$(
if [[ $- =~ H ]]; then
sed 's/^ *\([0-9]*\)\** .*/!\1/' <<< "$line"
else
sed 's/^ *\([0-9]*\)\** *//' <<< "$line"
fi
)
case $key in
$edit_key) result=$result$__fzf_edit_suffix__;;
$exec_key) result=$result$__fzf_exec_suffix__;;
esac
echo "$result"
else
# Ensure that no new line gets produced by CTRL-X CTRL-P.
echo "$__fzf_edit_suffix__"
fi
)
__fzf_edit_suffix__=#FZFEDIT#
__fzf_exec_suffix__=#FZFEXEC#
__fzf_rebind_ctrl_x_ctrl_p__() {
if test "${READLINE_LINE: -${#__fzf_edit_suffix__}}" = "$__fzf_edit_suffix__"; then
READLINE_LINE=${READLINE_LINE:0:-${#__fzf_edit_suffix__}}
bind '"\C-x\C-p": ""'
elif test "${READLINE_LINE: -${#__fzf_exec_suffix__}}" = "$__fzf_exec_suffix__"; then
READLINE_LINE=${READLINE_LINE:0:-${#__fzf_exec_suffix__}}
bind '"\C-x\C-p": accept-line'
fi
}
bind '"\C-x\C-p": ""'
bind -x '"\C-x\C-o": __fzf_rebind_ctrl_x_ctrl_p__'
if [[ ! -o vi ]]; then
bind '"\C-r": " \C-e\C-u\C-y\ey\C-u`__fzf_history__`\e\C-e\er\e^\C-x\C-o\C-x\C-p"'
else
bind '"\C-x\C-a": vi-movement-mode'
bind '"\C-x\C-e": shell-expand-line'
bind '"\C-x\C-r": redraw-current-line'
bind '"\C-x^": history-expand-line'
bind '"\C-r": "\C-x\C-addi`__fzf_history__`\C-x\C-e\C-x\C-r\C-x^\C-x\C-a$a\C-x\C-o\C-x\C-p"'
fi