###-begin-{pkgname}-completion-###
### credits to npm, this file is coming directly from isaacs/npm repo
#
# Just testing for now. (trying to learn this cool stuff)
#
# npm command completion script
#
# Installation: {completer} completion >> ~/.bashrc  (or ~/.zshrc)
#

COMP_WORDBREAKS=${COMP_WORDBREAKS/=/}
COMP_WORDBREAKS=${COMP_WORDBREAKS/@/}
export COMP_WORDBREAKS

if complete &>/dev/null; then
  _{pkgname}_completion () {
    local si="$IFS"
    IFS=$'\n' COMPREPLY=($(COMP_CWORD="$COMP_CWORD" \
                           COMP_LINE="$COMP_LINE" \
                           COMP_POINT="$COMP_POINT" \
                           {completer} completion -- "${COMP_WORDS[@]}" \
                           2>/dev/null)) || return $?
    IFS="$si"
  }
  complete -F _{pkgname}_completion -o default {pkgname}
elif compctl &>/dev/null; then
  _{pkgname}_completion () {
    local cword line point words si
    read -Ac words
    read -cn cword
    let cword-=1
    read -l line
    read -ln point
    si="$IFS"
    IFS=$'\n' reply=($(COMP_CWORD="${cword}" \
                       COMP_LINE="${(q)line}" \
                       COMP_POINT="${point}" \
                       {completer} completion -- "${(qq)words[@]}" \
                       2>/dev/null)) || return $?
    IFS="$si"
  }
  compctl -K _{pkgname}_completion {pkgname}
fi
###-end-{pkgname}-completion-###
