diff options
| author | Akshay Nair <phenax5@gmail.com> | 2020-12-23 23:40:35 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2020-12-23 23:40:35 +0530 |
| commit | 66adff9257c0bdcf5fea357cf4afd9c5804ac9d9 (patch) | |
| tree | 92b9941ed1b211594446c69e1c1a4d57240f1a0e /config/zsh/plugins/fzf-history.zsh | |
| parent | c69a505caac996f78b7b010dcc563672cb5a6019 (diff) | |
| download | nixos-config-66adff9257c0bdcf5fea357cf4afd9c5804ac9d9.tar.gz nixos-config-66adff9257c0bdcf5fea357cf4afd9c5804ac9d9.zip | |
Moves zsh config to config and symlinked
Diffstat (limited to 'config/zsh/plugins/fzf-history.zsh')
| -rw-r--r-- | config/zsh/plugins/fzf-history.zsh | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/config/zsh/plugins/fzf-history.zsh b/config/zsh/plugins/fzf-history.zsh new file mode 100644 index 0000000..f91cc99 --- /dev/null +++ b/config/zsh/plugins/fzf-history.zsh @@ -0,0 +1,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; |
