Bash completion for npx.
authorOleksandr Gavenko <gavenkoa@gmail.com>
Wed, 15 Sep 2021 15:22:14 +0300
changeset 992 d9cb7673d29c
parent 991 57fda390e91c
child 993 43ccab60bb32
Bash completion for npx.
.bash_completion.d/npx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.bash_completion.d/npx	Wed Sep 15 15:22:14 2021 +0300
@@ -0,0 +1,18 @@
+# -*- 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