Last active
May 8, 2020 11:28
-
-
Save ptek/ac6bd512f9601c7a420f815a1de1c0b9 to your computer and use it in GitHub Desktop.
(ZSH) Bind CTRL-R to search using fzy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Key bindings | |
# ------------ | |
if [[ $- == *i* ]]; then | |
# CTRL-R - Paste the selected command from history into the command line | |
fzy-history-widget() { | |
local selected num | |
setopt localoptions noglobsubst noposixbuiltins pipefail 2> /dev/null | |
selected=( $(fc -rl 1 | fzy) ) | |
local ret=$? | |
if [ -n "$selected" ]; then | |
num=$selected[1] | |
if [ -n "$num" ]; then | |
zle vi-fetch-history -n $num | |
fi | |
fi | |
zle reset-prompt | |
return $ret | |
} | |
zle -N fzy-history-widget | |
bindkey '^R' fzy-history-widget | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment