diff options
author | Stefan Maric <alexstefan92@gmail.com> | 2015-09-09 10:59:16 -0430 |
---|---|---|
committer | Fabian Homborg <FHomborg@gmail.com> | 2015-09-12 12:12:21 +0200 |
commit | 527c932e9396ed9c37dccc632543aa88330dbfcd (patch) | |
tree | 4e63fabcec0c8e8651f573d8ae968ab92a57dc7a | |
parent | cba3db6205a7cc3f7afcac1bffd4e7e951f25cea (diff) |
Fix npm run completion executing only on completions load, also:
* Better handling of `npm run` output
-rw-r--r-- | share/completions/npm.fish | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/share/completions/npm.fish b/share/completions/npm.fish index 4120b3a9..05393b85 100644 --- a/share/completions/npm.fish +++ b/share/completions/npm.fish @@ -58,6 +58,21 @@ end # and: https://github.com/fish-shell/fish-shell/pull/2366 complete -f -c npm -n 'not __fish_npm_needs_option' -a "(__fish_complete_npm)" +# list available npm scripts and their parial content +function __fish_npm_run + command npm run | command grep -v '^[^ ]' | command grep -v '^$' | command sed "s/^ *//" | while read -l name + set -l trim 20 + read -l value + echo "$value" | cut -c1-$trim | read -l value + printf "%s\t%s\n" $name $value + end +end + +# run +for c in run run-script + complete -f -c npm -n "__fish_npm_using_command $c" -a "(__fish_npm_run)" +end + # cache complete -f -c npm -n '__fish_npm_needs_command' -a 'cache' -d "Manipulates package's cache" complete -f -c npm -n '__fish_npm_using_command cache' -a 'add' -d 'Add the specified package to the local cache' @@ -123,14 +138,6 @@ for c in 'up' 'update' complete -f -c npm -n "__fish_npm_using_command $c" -s g -l global -d 'Update global package(s)' end -# run -command npm run | command tail -n +2 | command sed "s/^ *//" | while read -l name - set -l trim 20 - read -l value - complete -f -c npm -n "__fish_npm_using_command run" -a (printf "%s " "$name") -d (echo "$value" | cut -c1-$trim) - complete -f -c npm -n "__fish_npm_using_command run-script" -a (printf "%s " "$name") -d (echo "$value" | cut -c1-$trim) -end - # misc shorter explanations complete -f -c npm -n '__fish_npm_needs_command' -a 'adduser add-user login' -d 'Add a registry user account' complete -f -c npm -n '__fish_npm_needs_command' -a 'bin' -d 'Display npm bin folder' |