.bash_completion.d/npx
author Oleksandr Gavenko <gavenkoa@gmail.com>
Mon, 01 Jan 2024 20:53:49 +0200
changeset 1039 78cdb4a057e3
parent 992 d9cb7673d29c
permissions -rw-r--r--
Create symlink from ~/.bash_profile for login shell to activate my ~/.bashrc.

# -*- 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