Last active
December 17, 2017 16:27
-
-
Save funollet/2921ce5dd8bbf3bbfd243232b2606305 to your computer and use it in GitHub Desktop.
Dummy example of using fzf with GNU readline in Bash
This file contains hidden or 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
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