Skip to content
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

ZSH is the default in OSX Catalina and later #15

Open
AlfredJKwack opened this issue Feb 4, 2022 · 2 comments
Open

ZSH is the default in OSX Catalina and later #15

AlfredJKwack opened this issue Feb 4, 2022 · 2 comments

Comments

@AlfredJKwack
Copy link

Apple will set the Zsh as the default for any new user account that is created in macOS Catalina or later.
As a consequence the OSX setup script is likely outdated since it's assuming bash as the shell environment.

@ranguard
Copy link
Owner

ranguard commented Feb 5, 2022

I'm happy to take pull request - but we need to support both old and new OSX's

@AlfredJKwack
Copy link
Author

AlfredJKwack commented Feb 10, 2022

Fair enough @ranguard

As a starting point I would approach shell detection like the below.

if [ -n "`$SHELL -c 'echo $ZSH_VERSION'`" ]; then
   # assume Zsh
elif [ -n "`$SHELL -c 'echo $BASH_VERSION'`" ]; then
   # assume Bash
else
   # assume something else
fi

ZSH doesn't have to deal with notions such as .bashrc and .bash_profile. The ZSH loading order for both interactive login and non-login go through ~/.zshrc (see ref). That being said, perlbrew recommends using ~/.zshenv which also includes non-interactive shells so we can go with that. All of that to say that L39:L56 could be skipped entirely where ZSH is concerned

echo -n "Checking for .bash_profile... "
if [ -f $BASHP ]; then
echo "FOUND"
echo -n "Checking for .bashrc sourcing inside of .bash_profile... "
if [ "" != "$( cat $BASHP | grep 'source ' | grep 'bashrc' )" ]; then
echo "FOUND"
else
echo "NOT FOUND"
echo "Adding 'source $BASHR' to $BASHP"
echo "# Added by install_latest_perl_osx.pl" >>$BASHP
echo "[ -r $BASHR ] && source $BASHR" >>$BASHP
fi
else
echo "NOT FOUND"
echo "Creating $BASHP"
echo "# Added by install_latest_perl_osx.pl" >>$BASHP
echo "[ -r $BASHR ] && source $BASHR" >>$BASHP
fi

A refactoring of L76-L85 could accommodate both ZSH and BASH notions since the only variable is the file we're writing out to.

echo "Checking/updating $BASHR to source perlbrew bashrc"
if [ ! -f $BASHR ]; then
# File missing so create
echo "source $PBREW_BASHRC" >> $BASHR
else
if [ "" == "$( cat $BASHR | grep 'source ' | grep $PBREW_BASHRC )" ]; then
# source line is missing - so add
echo "source $PBREW_BASHRC" >> $BASHR
fi;
fi;

The last thing, and this is beyond the scope of this issue is the ARCHFLAGS. Since Apple decided to switch to its own silicon from Intel's I'm not sure whether it's worth adding a flag in support of 'uname -m' == 'arm64' or $(uname -p) == 'arm'. What's your take on that?

# Build as i386 only
arch=`uname -m`
if [ "$arch" == 'i386' ]; then
echo 'export ARCHFLAGS="-arch i386"' >> ~/perl5/perlbrew/etc/bashrc
fi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants