.bash_completion.d/npx
author Oleksandr Gavenko <gavenkoa@gmail.com>
Sun, 25 Dec 2022 21:06:07 +0200
changeset 1012 5db0edb5ff00
parent 992 d9cb7673d29c
permissions -rw-r--r--
OrangeRed is not recognized by mintty, used hex code instead.

# -*- mode: sh; sh-shell-file: bash -*-

_npx() {
  local dir=$(pwd -P)
  while [[ -n "$dir" ]]; do
    if [[ ! -d $dir/node_modules/.bin ]]; then
      dir=${dir%/*}
      continue
    fi
    local execs=( `cd $dir/node_modules/.bin; find -L . -type f -executable` )
    execs=( ${execs[@]/#.\//} )
    local cur=${COMP_WORDS[COMP_CWORD]}
    COMPREPLY=( $(compgen -W "${execs[*]}" -- "$cur" ) )
    break
  done
}

complete -F _npx npx