I'd like to install a zsh completion script for a CLI tool when it's
installed globally (i.e. npm install -g). This would mean putting a file in
/usr/share/zsh/site-functions (or wherever zsh was installed). That usually
requires root permissions. When testing this with an install script, it
fails. Checking the documentation, I see
o Don't prefix your script commands with "sudo". If root
permissions are required for some reason,
then it'll fail with that error, and the user will sudo the npm
command in question.
So a "sudo npm install -g" would run the script as root? No:
If npm was invoked with root privileges, then it will change the uid
to the user account or uid spec-
ified by the user config, which defaults to nobody. Set the
unsafe-perm flag to run scripts with
So is there no way to get the install script to run with root privs (apart
from setting 'unsafe-perm')? Using sudo from within the script itself
wouldn't work either, since it's run as nobody...
Is this simply outside the scope of npm, hence not supported and I should
implement something like "mycommand install-completion" instead, to be used
after the installation is complete?