* [PATCH] Prevent npm completion from spamming update notifications
@ 2018-11-09 12:26 dana
0 siblings, 0 replies; only message in thread
From: dana @ 2018-11-09 12:26 UTC (permalink / raw)
To: Zsh workers
Newer versions of npm (and maybe older ones? but i never encountered it until
now) check for updates whenever you run literally any sub-command, including the
one that handles completion, and if it thinks it has something important to tell
you about that it spams the screen with colourful ASCII-art boxes of nonsense
Fortunately the spam only makes its way to the screen once per session, since
every time after that _npm_completion redirects it to /dev/null. But the npm
call in _npm_completion is still wasting time on the update check/notification
even when it's not showing the result. So i offer two possible fixes:
1. A conservative one that suppresses the visible spam but leaves the time-
wasting checks
2. A more complete but possibly questionable one that monkey-patches their
_npm_completion to avoid the time-wasting checks
Is the second one too weird to ship with the shell?
(Both patches also change the type call to a $commands check)
dana
### CONSERVATIVE PATCH ###
diff --git a/Completion/Unix/Command/_npm b/Completion/Unix/Command/_npm
index f5493a321..d069fc107 100644
--- a/Completion/Unix/Command/_npm
+++ b/Completion/Unix/Command/_npm
@@ -2,8 +2,8 @@
# Node Package Manager completion, letting npm do all the completion work
-if type npm > /dev/null; then
- eval "$(npm completion)"
+if (( $+commands[npm] )); then
+ eval "$(NPM_CONFIG_UPDATE_NOTIFIER=false npm completion)"
_npm_completion "$@"
fi
### FUNNY PATCH ####
diff --git a/Completion/Unix/Command/_npm b/Completion/Unix/Command/_npm
index f5493a321..c05f61c51 100644
--- a/Completion/Unix/Command/_npm
+++ b/Completion/Unix/Command/_npm
@@ -2,8 +2,13 @@
# Node Package Manager completion, letting npm do all the completion work
-if type npm > /dev/null; then
- eval "$(npm completion)"
+if (( $+commands[npm] )); then
+ eval "$(NPM_CONFIG_UPDATE_NOTIFIER=false npm completion)"
+ # Monkey-patch their function to prevent update checks
+ functions[_npm_completion]="
+ local -x NPM_CONFIG_UPDATE_NOTIFIER=false;
+ ${functions[_npm_completion]}
+ "
_npm_completion "$@"
fi
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2018-11-09 12:25 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-09 12:26 [PATCH] Prevent npm completion from spamming update notifications dana
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).