|
|
@ -11,9 +11,9 @@ _zbnc_recursively_look_for() { |
|
|
|
local dir=$PWD |
|
|
|
while [ ! -e "$dir/$filename" ]; do |
|
|
|
dir=${dir%/*} |
|
|
|
[ "$dir" = "" ] && break |
|
|
|
[[ "$dir" = "" ]] && break |
|
|
|
done |
|
|
|
[ ! "$dir" = "" ] && echo "$dir/$filename" |
|
|
|
[[ ! "$dir" = "" ]] && echo "$dir/$filename" |
|
|
|
} |
|
|
|
|
|
|
|
_zbnc_parse_package_json_for_script_suggestions() { |
|
|
@ -29,7 +29,7 @@ _zbnc_parse_package_json_for_script_suggestions() { |
|
|
|
_zbnc_npm_install_completion() { |
|
|
|
|
|
|
|
# Only run on `npm install ?` |
|
|
|
[ ! "$(_zbnc_no_of_npm_args)" = "3" ] && return |
|
|
|
[[ ! "$(_zbnc_no_of_npm_args)" = "3" ]] && return |
|
|
|
|
|
|
|
# Reccomend cached modules |
|
|
|
_values $(ls ~/.npm) |
|
|
@ -41,20 +41,20 @@ _zbnc_npm_install_completion() { |
|
|
|
_zbnc_npm_run_completion() { |
|
|
|
|
|
|
|
# Only run on `npm run ?` |
|
|
|
[ ! "$(_zbnc_no_of_npm_args)" = "3" ] && return |
|
|
|
[[ ! "$(_zbnc_no_of_npm_args)" = "3" ]] && return |
|
|
|
|
|
|
|
# Look for a package.json file |
|
|
|
local package_json="$(_zbnc_recursively_look_for package.json)" |
|
|
|
|
|
|
|
# Return if we can't find package.json |
|
|
|
[ "$package_json" = "" ] && return |
|
|
|
[[ "$package_json" = "" ]] && return |
|
|
|
|
|
|
|
# Parse scripts in package.json |
|
|
|
local -a options |
|
|
|
options=(${(f)"$(_zbnc_parse_package_json_for_script_suggestions $package_json)"}) |
|
|
|
|
|
|
|
# Return if we can't parse it |
|
|
|
[ "$#options" = 0 ] && return |
|
|
|
[[ "$#options" = 0 ]] && return |
|
|
|
|
|
|
|
# Load the completions |
|
|
|
_describe 'values' options |
|
|
@ -87,7 +87,7 @@ _zbnc_zsh_better_npm_completion() { |
|
|
|
esac |
|
|
|
|
|
|
|
# Fall back to default completion if we haven't done a custom one |
|
|
|
[ $custom_completion = false ] && _zbnc_default_npm_completion |
|
|
|
[[ $custom_completion = false ]] && _zbnc_default_npm_completion |
|
|
|
} |
|
|
|
|
|
|
|
compdef _zbnc_zsh_better_npm_completion npm |
|
|
|