Created
December 24, 2014 22:42
-
-
Save dualbus/0fcfda4a024ad0f2f962 to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
save=$(bind -p; bind -X) | |
function clean-up { | |
bind -r '\C-i' | |
bind -f /dev/stdin <<< "$save" | |
} | |
trap 'clean-up' RETURN | |
function write-options { | |
typeset o | |
for o do | |
printf '* %s\n' "$o" | |
done | |
printf '%s\n' -- | |
} >&2 | |
function complete-e { | |
typeset o nicks=$1 | |
typeset -a opts=() | |
typeset -a matches=() | |
mapfile -t opts < "$nicks" | |
for o in "${opts[@]}"; do | |
[[ $o = "$READLINE_LINE"* ]] && matches+=("$o") | |
done | |
if (( ${#matches[@]} == 1 )); then | |
READLINE_LINE="$matches " | |
READLINE_POINT=$(( ${#matches} + 1 )) | |
else | |
write-options "${matches[@]}" | |
fi | |
} | |
bind -x '"\C-i":complete-e /dev/fd/3' | |
read -e -p 'nick> ' nick 3<<NICKS | |
llua | |
lhunath | |
geirha | |
duck | |
dualbus | |
ormaaj | |
NICKS | |
echo "nick was: $nick" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment