Skip to content

Commit 70a0b5a

Browse files
committed
shell: Add history search shortcut
1 parent 530defa commit 70a0b5a

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

zsh/.zutils

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,21 +80,37 @@ function _fzf_dev {
8080
zle -N _fzf_dev
8181
bindkey '^F' _fzf_dev
8282

83+
function fzf_history {
84+
history -in -1 0 | \
85+
fzf --border=rounded \
86+
--margin=2,16 \
87+
--prompt="History » " \
88+
--pointer=▶ \
89+
-1 \
90+
--query "$1" | \
91+
awk -F' ' '{print $2}'
92+
}
93+
8394
function hist {
84-
selected_cmd=$(history -in -1 0 | \
85-
fzf --border=rounded \
86-
--margin=2,16 \
87-
--prompt="History » " \
88-
--pointer=▶ \
89-
-1 \
90-
--query "$1" | \
91-
awk -F' ' '{print $2}')
95+
selected_cmd=$(fzf_history $1)
9296

9397
if [[ -n "$selected_cmd" ]]; then
9498
eval $selected_cmd
9599
fi
96100
}
97101

102+
function _fzf_hist {
103+
selected_cmd=$(fzf_history $LBUFFER)
104+
105+
if [[ -n "$selected_cmd" ]]; then
106+
BUFFER="$selected_cmd"
107+
zle accept-line
108+
fi
109+
}
110+
111+
zle -N _fzf_hist
112+
bindkey '^r' _fzf_hist
113+
98114
function fapt() {
99115
local pkg
100116
pkg=$(apt-cache search '.*' | fzf -m | awk '{print $1}')

0 commit comments

Comments
 (0)