From: dana <dana@dana.is>
To: Zsh workers <zsh-workers@zsh.org>
Subject: [PATCH] Prevent npm completion from spamming update notifications
Date: Fri, 9 Nov 2018 06:26:04 -0600 [thread overview]
Message-ID: <849C47D0-AC5A-46C1-AEF1-4740F79433D1@dana.is> (raw)
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
reply other threads:[~2018-11-09 12:25 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=849C47D0-AC5A-46C1-AEF1-4740F79433D1@dana.is \
--to=dana@dana.is \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).