blob: f91cc994083796da838eb4791b2e0f3abc4c48fd (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
full_history() {
[[ ${@[-1]-} = *[0-9]* ]] && builtin fc -l "$@" || builtin fc -l "$@" 1;
}
trim() { sed 's/^\s*//g'; }
reverse() { sed -n '1!G;h;$p'; }
unique() { awk '!seen[$0]++'; }
search_history() {
local result=$(full_history | trim | cut -d' ' -f 2- | reverse | unique | fzf);
# Replace the buffer with the editor output.
print -Rz - "$(echo -n "$result" | trim)";
zle send-break # Force reload from the buffer stack
}
zle -N search_history;
bindkey '^R' search_history;
|