Skip to content

Instantly share code, notes, and snippets.

@EgZvor
Created August 15, 2019 23:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EgZvor/b237a9c324f8fd5b15480ed61d1dff67 to your computer and use it in GitHub Desktop.
Save EgZvor/b237a9c324f8fd5b15480ed61d1dff67 to your computer and use it in GitHub Desktop.
fzy bindings for zsh mirrored from fzf and simplified
# CTRL-T - Paste the selected file path(s) into the command line
__fsel() {
setopt localoptions pipefail 2> /dev/null
rg --files --hidden --glob '!.git/' | fzy
local ret=$?
echo
return $ret
}
fzy-file-widget() {
LBUFFER="${LBUFFER}$(__fsel)"
local ret=$?
zle reset-prompt
return $ret
}
zle -N fzy-file-widget
bindkey '^T' fzy-file-widget
# 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 '^X^R' fzy-history-widget
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment