Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
[PATCH] Prevent npm completion from spamming update notifications
- X-seq: zsh-workers 43809
- From: dana <dana@xxxxxxx>
- To: Zsh workers <zsh-workers@xxxxxxx>
- Subject: [PATCH] Prevent npm completion from spamming update notifications
- Date: Fri, 9 Nov 2018 06:26:04 -0600
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dana-is.20150623.gappssmtp.com; s=20150623; h=from:content-transfer-encoding:mime-version:subject:message-id:date :to; bh=heDyB3XEK+deTgZn+hnNq+2/mSVaFjtzUYn4ZfxR6aM=; b=cUVoAKyWLj2aocQ3rvIOVuoqOliSJjIhzUI0VjMq0lasb+JDmimOqbVP2Sow1X9cAQ Y2k29l460e6cQkWFXliqqgQMF1KUShiqalDl3gTBOLX/DTQLKigFgnn/B7pjdhpapy8X BsCjq/nUgFDCbxCCG9OvCwRvRjPee2EOyVs3wqPnsqlTiemwyyN6LYc+ABfNk27pqHu1 /dM1MHxFst9imC5CHF4LdD2InjTMewXksJ0flcYyFp1/J+pByZgR9rcTtUBHU5VpE9PJ onQ2AJIOIE0lHn5SwUKcPTjJsEW1WQV4hprGkVC7Ly4jke9p+x/JViJSlJ+udpi8Nd45 LyGA==
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author