complete -r rsnip > /dev/null 2>&1
_rsnip_complete() {
local cur prev
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
local commands="copy edit list types"
if [[ ${COMP_CWORD} -eq 1 ]]; then
COMPREPLY=( $(compgen -W "${commands}" -- ${cur}) )
return 0
fi
local snippet_types=$(rsnip --info 2>/dev/null | grep "Available types:" | cut -d':' -f2)
case "${prev}" in
"--ctype"|"-c")
COMPREPLY=( $(compgen -W "${snippet_types}" -- ${cur}) )
return 0
;;
"complete"|"copy"|"xxx")
COMPREPLY=( $(compgen -W "--ctype --input --interactive" -- ${cur}) )
return 0
;;
esac
local ctype=""
for ((i=1; i<COMP_CWORD; i++)); do
if [[ "${COMP_WORDS[i]}" == "--ctype" || "${COMP_WORDS[i]}" == "-c" ]]; then
ctype="${COMP_WORDS[i+1]}"
break
fi
done
if [[ -n "${ctype}" && "${prev}" == "--input" ]]; then
tput smcup
local result
result="$(rsnip complete --interactive --ctype "${ctype}" --input "${cur}")"
tput rmcup
if [[ -n "$result" ]]; then
COMPREPLY=("$result")
printf '\e[5n'
fi
fi
}
if [[ :"${SHELLOPTS}": =~ :(vi|emacs): && ${TERM} != 'dumb' ]]; then
bind '"\e[0n": redraw-current-line' &>/dev/null
fi
complete -F _rsnip_complete rsnip