Browse Source

Add completions for npx (#12)

master
Hlöðver Sigurðsson 2 months ago
committed by GitHub
parent
commit
02ca404a9b
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 32
      zsh-better-npm-completion.plugin.zsh

32
zsh-better-npm-completion.plugin.zsh

@ -141,3 +141,35 @@ _zbnc_zsh_better_npm_completion() {
}
compdef _zbnc_zsh_better_npm_completion npm
# npx completions
_zbnc_npx_list_excuteables() {
local package_json="$1"
local node_modules="$(dirname package_json)/node_modules"
local bindir="$node_modules/.bin"
# Return if there's no node_modules
[[ ! -e "$node_modules" ]] && return
# Return if there's no .bin in node_modules
[[ ! -e "$bindir" ]] && return
ls $bindir 2>/dev/null
}
_zbnc_zsh_better_npm_completion_npx() {
local package_json="$(_zbnc_recursively_look_for package.json)"
# Return if we can't find package.json
[[ "$package_json" = "" ]] && return
_values $(_zbnc_npx_list_excuteables "$package_json")
# Make sure we don't run default completion
custom_completion=true
}
compdef _zbnc_zsh_better_npm_completion_npx npx

Loading…
Cancel
Save