Skip to content

Instantly share code, notes, and snippets.

@dualbus
Created December 24, 2014 22:42
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dualbus/0fcfda4a024ad0f2f962 to your computer and use it in GitHub Desktop.
Save dualbus/0fcfda4a024ad0f2f962 to your computer and use it in GitHub Desktop.
#!/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