• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2###-begin-npm-completion-###
3#
4# npm command completion script
5#
6# Installation: npm completion >> ~/.bashrc  (or ~/.zshrc)
7# Or, maybe: npm completion > /usr/local/etc/bash_completion.d/npm
8#
9
10if type complete &>/dev/null; then
11  _npm_completion () {
12    local words cword
13    if type _get_comp_words_by_ref &>/dev/null; then
14      _get_comp_words_by_ref -n = -n @ -n : -w words -i cword
15    else
16      cword="$COMP_CWORD"
17      words=("${COMP_WORDS[@]}")
18    fi
19
20    local si="$IFS"
21    IFS=$'\n' COMPREPLY=($(COMP_CWORD="$cword" \
22                           COMP_LINE="$COMP_LINE" \
23                           COMP_POINT="$COMP_POINT" \
24                           npm completion -- "${words[@]}" \
25                           2>/dev/null)) || return $?
26    IFS="$si"
27    if type __ltrim_colon_completions &>/dev/null; then
28      __ltrim_colon_completions "${words[cword]}"
29    fi
30  }
31  complete -o default -F _npm_completion npm
32elif type compdef &>/dev/null; then
33  _npm_completion() {
34    local si=$IFS
35    compadd -- $(COMP_CWORD=$((CURRENT-1)) \
36                 COMP_LINE=$BUFFER \
37                 COMP_POINT=0 \
38                 npm completion -- "${words[@]}" \
39                 2>/dev/null)
40    IFS=$si
41  }
42  compdef _npm_completion npm
43elif type compctl &>/dev/null; then
44  _npm_completion () {
45    local cword line point words si
46    read -Ac words
47    read -cn cword
48    let cword-=1
49    read -l line
50    read -ln point
51    si="$IFS"
52    IFS=$'\n' reply=($(COMP_CWORD="$cword" \
53                       COMP_LINE="$line" \
54                       COMP_POINT="$point" \
55                       npm completion -- "${words[@]}" \
56                       2>/dev/null)) || return $?
57    IFS="$si"
58  }
59  compctl -K _npm_completion npm
60fi
61###-end-npm-completion-###
62