Skip to content

Instantly share code, notes, and snippets.

@Gordin
Last active August 29, 2015 14:25
Show Gist options
  • Save Gordin/7514816a29760686ab88 to your computer and use it in GitHub Desktop.
Save Gordin/7514816a29760686ab88 to your computer and use it in GitHub Desktop.
Selecta history widget for zsh
if [[ -n $(which selecta) ]]; then
# CTRL-R - Paste the selected command from history into the command line
selecta-history-widget() {
local selected restore_no_bang_hist
if [[ -z "$LBUFFER" ]]; then
selected=( $(fc -l 1 | selecta) )
else
selected=( $(fc -l 1 | selecta -s "$LBUFFER") )
fi
if $selected; then
num=$selected[1]
if [ -n "$num" ]; then
zle vi-fetch-history -n $num
fi
fi
zle redisplay
}
zle -N selecta-history-widget
bindkey '^R' selecta-history-widget
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment