diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c374498c..249c60d8b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -69,8 +69,11 @@ This section is for changes merged to the `major` branch that are not also merge - `brew` - `diskutil` - `git` (#4395, #4396, #4592) + - `npm` - `ssh` (#4344) - - `yarn` + - `yarn` + +_† for autocompletion of available packages for installation via `npm` or `yarn`, make sure `all-the-package-names` is installed (typically: `sudo npm install -g all-the-package-names`)._ -- diff --git a/share/completions/npm.fish b/share/completions/npm.fish index 0ae9dcdc2..ff9731c8d 100644 --- a/share/completions/npm.fish +++ b/share/completions/npm.fish @@ -4,31 +4,14 @@ # see also Fish's large set of completions for examples: # https://github.com/fish-shell/fish-shell/tree/master/share/completions -set -g __fish_atpm_cache $HOME/.cache/fish/npm_completions - -function __install_atpm - if not test -d $__fish_atpm_cache - mkdir -p $__fish_atpm_cache - fish -c "cd $HOME/.cache/fish/npm_completions; npm init -y >/dev/null; npm install all-the-package-names >/dev/null; touch .last_update" >/dev/null 2>/dev/null - end -end - -function __update_atpm - if test \"(find $__fish_atpm_cache/ -name .last_update -mtime +1 -print)\" - # all-the-package-names is out of date - fish -c "cd $__fish_atpm_cache; npm update; touch .last_update" >/dev/null 2>/dev/null - end -end - +# If all-the-package-names is installed, it will be used to generate npm completions. +# Install globally with `sudo npm install -g all-the-package-names`. Keep it up to date. function __npm_list_packages - if not test -x $__fish_atpm_cache/node_modules/.bin/all-the-package-names - if not __install_atpm >/dev/null - return - end + if not type -q all-the-package-names + return end - __update_atpm >/dev/null - eval $__fish_atpm_cache/node_modules/.bin/all-the-package-names + all-the-package-names end # Entire list of packages is too long to be used in a `complete` subcommand