Skip to content

Instantly share code, notes, and snippets.

@funollet
Last active December 17, 2017 16:27
Show Gist options
  • Save funollet/2921ce5dd8bbf3bbfd243232b2606305 to your computer and use it in GitHub Desktop.
Save funollet/2921ce5dd8bbf3bbfd243232b2606305 to your computer and use it in GitHub Desktop.
Dummy example of using fzf with GNU readline in Bash
fzfsimple () {
local out
out=$(echo -e 'pim\npam\npum' | fzf )
# Append to current line.
READLINE_LINE="${READLINE_LINE}${out}"
# Optional: move cursor to end of line.
READLINE_POINT=${#READLINE_LINE}
}
fzfdemo () {
local out
out=$(echo -e 'pim\npam\npum' | fzf )
# Insert into current line.
pre="${READLINE_LINE:0:$READLINE_POINT}"
post="${READLINE_LINE:$READLINE_POINT}"
READLINE_LINE="${pre}${out}${post}"
READLINE_POINT=$(( ${#pre} + ${#out} ))
}
# Bind to 'Alt+0' and 'Alt+1'.
bind -x '"\e0":"fzfsimple"'
bind -x '"\e1":"fzfdemo"'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment