Skip to content

Instantly share code, notes, and snippets.

@ptek
Last active May 8, 2020 11:28
Show Gist options
  • Save ptek/ac6bd512f9601c7a420f815a1de1c0b9 to your computer and use it in GitHub Desktop.
Save ptek/ac6bd512f9601c7a420f815a1de1c0b9 to your computer and use it in GitHub Desktop.
(ZSH) Bind CTRL-R to search using fzy
# 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