Skip to content

Please fix the setup script for macOS #3558

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
anton-bedrock opened this issue Apr 6, 2025 · 10 comments
Open

Please fix the setup script for macOS #3558

anton-bedrock opened this issue Apr 6, 2025 · 10 comments
Labels
installing nvm: profile detection Issues with nvm's own install script, related to figuring out the right profile file. shell: zsh

Comments

@anton-bedrock
Copy link

On macOS there setup script mentioned bash completions, but it should be zsh completions instead. An easy fix, but it will save hours for many macOS users. Please fix it.

After running the following command to install NVM.

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.2/install.sh | bash

my .zshrc file had the following added.

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

After restarting the terminal, it appeared.

zsh compinit: insecure directories, run compaudit for list.
Ignore insecure directories and continue [y] or abort compinit [n]?

After changing bash_completion to zsh_completion, the error disappeared.

Originally posted by @amlzq in #2361

@ljharb
Copy link
Member

ljharb commented Apr 7, 2025

Not all Mac OS users use zsh, so it definitely shouldn’t do it by platform.

@ljharb ljharb added shell: zsh installing nvm: profile detection Issues with nvm's own install script, related to figuring out the right profile file. labels Apr 7, 2025
@anton-bedrock
Copy link
Author

anton-bedrock commented Apr 7, 2025

@ljharb said:

Not all Mac OS users use zsh, so it definitely shouldn’t do it by platform.

I think last 2-3 years macOS ships with zsh. So you always can check if zsh is available and use one output, with a fallback to bash. Seems an easy check

@ljharb
Copy link
Member

ljharb commented Apr 7, 2025

Yes, that's true, but if you've continuously migrated your Mac environment from prior to that, then you'll stay on bash, as I have.

zsh is always available now, that can't be used to make a choice.

I have a .bashrc, .bash_profile, and .zshrc present, but bash is my default. What logic would you suggest that can select "bash" for me but "zsh" for you?

@sdavids
Copy link

sdavids commented Apr 11, 2025

https://support.apple.com/en-us/102360

zsh (Z shell) is the default shell for all newly created user accounts, starting with macOS Catalina.

https://en.wikipedia.org/wiki/MacOS_Catalina

macOS Catalina [was] released to the public on October 7, 2019

https://endoflife.date/macos

macOS 10.15 (Catalina) support ended 12 Sep 2022

@sdavids
Copy link

sdavids commented Apr 11, 2025

if you've continuously migrated your Mac environment from prior to that

Not everybody is as old as we are 😉

@anton-bedrock
Copy link
Author

I have a .bashrc, .bash_profile, and .zshrc present, but bash is my default. What logic would you suggest that can select "bash" for me but "zsh" for you?

You always can see in which shell you run the installation script (bash, zsh, etc), right? Depending on it you can write to terminal the correct instructions. I think you can see how other projects achieve this. Or if no luck with detection, write few possible lines - each for each supported shell.

@sdavids
Copy link

sdavids commented Apr 11, 2025

https://stackoverflow.com/questions/3327013/how-to-determine-the-current-interactive-shell-that-im-in-command-line

Unfortunately, the output of ps -p $$ is not standardized and some terminals report it incorrectly.

$BASH or $ZSH_NAME usually indicate the shell used but it is not reliable either.

But I think a 90% solution is better then doing nothing:

If $ZSH_NAME or ps -p $$ contains the string zsh do the zsh installation otherwise do the bash installation.

@ljharb
Copy link
Member

ljharb commented Apr 11, 2025

I'd be happy to review a PR that did that - noting that the install script must always run in bash.

@sdavids
Copy link

sdavids commented Apr 13, 2025

I experimented a little:

$ sw_vers
ProductName:	macOS
ProductVersion:	12.7.6
BuildVersion:	21H1320
$ ps -p $$
  PID TTY           TIME CMD
77576 ttys002    0:00.20 -zsh
$ echo $SHELL
/bin/zsh
$ echo $ZSH_NAME
zsh

$ mkdir /tmp/test && cd "$_"
$ printf '#!/usr/bin/env bash\necho $(ps -p $$)\necho $SHELL\necho $BASH\necho $ZSH_NAME\n' >install.sh
$ chmod u+x install.sh

$ curl -so- file:///tmp/test/install.sh | zsh
PID TTY TIME CMD 78615 ttys001 0:00.01 zsh
/bin/zsh

zsh
$ curl -so- file:///tmp/test/install.sh | bash
PID TTY TIME CMD 78651 ttys001 0:00.01 bash
/bin/zsh
/usr/local/bin/bash

$ zsh -c 'curl -so- curl -so- file:///tmp/test/install.sh | zsh'
PID TTY TIME CMD 78691 ttys001 0:00.01 zsh
/bin/zsh

zsh
$ zsh -c 'curl -so- curl -so- file:///tmp/test/install.sh | bash'
PID TTY TIME CMD 78702 ttys001 0:00.01 bash
/bin/zsh
/usr/local/bin/bash

$  bash -c 'curl -so- curl -so- file:///tmp/test/install.sh | zsh'
PID TTY TIME CMD 78767 ttys001 0:00.01 zsh
/bin/zsh

zsh
$ bash -c 'curl -so- curl -so- file:///tmp/test/install.sh | bash'
PID TTY TIME CMD 78755 ttys001 0:00.01 bash
/bin/zsh
/usr/local/bin/bash

$ docker run -it --rm -v /tmp/test:/tmp/test ubuntu:noble-20250404 bash
# apt-get -y update && apt-get -y install curl
# curl -so- file:///tmp/test/install.sh | bash
PID TTY TIME CMD 2927 pts/0 00:00:00 bash
/bin/bash
/usr/bin/bash

# exit
$ docker run -it --rm -v /tmp/test:/tmp/test ubuntu:noble-20250404 bash
# apt-get -y update && apt-get -y install curl zsh
# zsh
# ps -p $$
  PID TTY          TIME CMD
 3025 pts/0    00:00:00 zsh
# curl -so- file:///tmp/test/install.sh | bash
PID TTY TIME CMD 3047 pts/0 00:00:00 bash
/bin/bash
/usr/bin/bash

# curl -so- file:///tmp/test/install.sh | zsh
PID TTY TIME CMD 3050 pts/0 00:00:00 zsh


zsh
# exit
# zsh -c 'curl -so- curl -so- file:///tmp/test/install.sh | bash'
PID TTY TIME CMD 3056 pts/0 00:00:00 bash
/bin/bash
/usr/bin/bash

# zsh -c 'curl -so- curl -so- file:///tmp/test/install.sh | zsh'
PID TTY TIME CMD 3061 pts/0 00:00:00 zsh


zsh

As expected, a mess 🫣

@sdavids
Copy link

sdavids commented Apr 13, 2025

There are three options:

  1. do nothing
  2. if one of ps -p $$, $SHELL, or $ZSH_NAME contains zsh then install zsh completions instead of bash completions
  3. same as 2. but also mention curl .../install.sh | zsh in docs

2. and 3. could either install zsh completions immediately or ask something along the lines "It seems that you are you using zsh; do you want to install zsh completions instead of bash completions?"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
installing nvm: profile detection Issues with nvm's own install script, related to figuring out the right profile file. shell: zsh
Projects
None yet
Development

No branches or pull requests

3 participants