.bash_completion.d/npx
author Oleksandr Gavenko <gavenkoa@gmail.com>
Wed, 29 Mar 2023 23:42:06 +0300
changeset 1018 831e2c1bf980
parent 992 d9cb7673d29c
permissions -rw-r--r--
Completed migration from ~/devel to ~/work.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
992
d9cb7673d29c Bash completion for npx.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     1
# -*- mode: sh; sh-shell-file: bash -*-
d9cb7673d29c Bash completion for npx.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     2
d9cb7673d29c Bash completion for npx.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     3
_npx() {
d9cb7673d29c Bash completion for npx.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     4
  local dir=$(pwd -P)
d9cb7673d29c Bash completion for npx.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     5
  while [[ -n "$dir" ]]; do
d9cb7673d29c Bash completion for npx.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     6
    if [[ ! -d $dir/node_modules/.bin ]]; then
d9cb7673d29c Bash completion for npx.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     7
      dir=${dir%/*}
d9cb7673d29c Bash completion for npx.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     8
      continue
d9cb7673d29c Bash completion for npx.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     9
    fi
d9cb7673d29c Bash completion for npx.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    10
    local execs=( `cd $dir/node_modules/.bin; find -L . -type f -executable` )
d9cb7673d29c Bash completion for npx.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    11
    execs=( ${execs[@]/#.\//} )
d9cb7673d29c Bash completion for npx.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    12
    local cur=${COMP_WORDS[COMP_CWORD]}
d9cb7673d29c Bash completion for npx.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    13
    COMPREPLY=( $(compgen -W "${execs[*]}" -- "$cur" ) )
d9cb7673d29c Bash completion for npx.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    14
    break
d9cb7673d29c Bash completion for npx.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    15
  done
d9cb7673d29c Bash completion for npx.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    16
}
d9cb7673d29c Bash completion for npx.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    17
d9cb7673d29c Bash completion for npx.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    18
complete -F _npx npx