shell aliases conflict with nvs.sh
In my zsh configuration, I have several common commands aliased to add common flags and options. In particular, the rm command is aliased to rm -i, which requires interactive responses for each file or directory to be removed.
E.g.,
➜ rm -r $HOME/.nvs/cache/node-v12.18.2-darwin-x64
examine files in directory /Users/jxb2016/.nvs/cache/node-v12.18.2-darwin-x64?
When running the install script, this causes the installer to hang:
➜ . "$NVS_HOME/nvs.sh" install
Downloading bootstrap node from https://nodejs.org/dist/v12.18.2/node-v12.18.2-darwin-x64.tar.xz
####################################################################################################### 100.0%
In another window, I see the install is hanging on the rm command I showed above:
➜ ps -eaf | grep nvs
501 37726 32842 0 9:54AM ttys000 0:00.00 rm -i -r /Users/jxb2016/.nvs/cache/node-v12.18.2-darwin-x64
After understanding why this was hanging, I was able to get the installer to run for me by running:
➜ unalias rm
➜ . "$NVS_HOME/nvs.sh" install
~/.zshrc += nvs.sh
Edit: this also effects other places where nvs.sh uses commands. E.g.:
➜ nvs use latest
PATH += ~/.nvs/node/14.10.1/x64/bin
remove /Users/jxb2016/.nvs/nvs_tmp_371926994.sh?
In bash, I know it's possible to use a command prefix to ignore aliases invoking shell commands. Does that work in other shells? (I'm not an expert in shell scripting.)
I'm surprised you don't have problems with other scripts, as I don't think it's common for shell scripts to universally use the command prefix. I could be wrong though.
The main reason this is having issues is that the script is sourced into the current shell instead of starting a subshell. With a plain script that is not sourced, bash will disable aliases by default. I believe that other tools like pyenv (which behaves somewhat similarly to nvs in that it gets sourced in and defines shell functions) typically locate where the real commands exist and run things using the full path to the commands.
In fact, pyenv specifically uses command to do that. It gets the results of command -v COMMANDNAME and saves that to a variable, and when it runs the commands, it uses the variable to run the command. E.g.:
https://github.com/pyenv/pyenv/blob/d1ae4a1225f1c7e714316c4079416bbc6f4d60b0/libexec/pyenv#L131-L148
Beware this example, though, depending on what you need to accomplish. The exec of the command could not be used from a shell function or from a sourced script, because that would replace the shell that the user is running in with the command, and when it finishes it will close the user's shell.
I see. So, given nvs works by sourcing the script, it does seem like would be better to use command to bypass any potential aliases.