5

As some of you may know, after upgrading to Mac OS Catalina, Apple is prompting users to migrate to zsh as the default shell.

Now, there is a warning that comes up every time bash is opened. It can be disabled adding the line below to your ~/.bash_profile (for those interested).

export BASH_SILENCE_DEPRECATION_WARNING=1

However, I figure that many (including me) want to move on to zsh.

My current ~/.bash_profile looks like below:

# searches this directory for executables first
export PATH="/usr/local/bin:$PATH"

# jenv
export PATH="$HOME/.jenv/bin:$PATH"
eval "$(jenv init -)"

# rbenv
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"

# pyenv
export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init -)"

# nodenv
export PATH="$HOME/.nodenv/bin:$PATH"
eval "$(nodenv init -)"

# node-build-definitions
export NODE_BUILD_DEFINITIONS="/usr/local/opt/node-build-update-defs/share/node-build"

# bash auto-completion
if [ -f $(brew --prefix)/etc/bash_completion ]; then
  . $(brew --prefix)/etc/bash_completion    
fi

# git branch in prompt
parse_git_branch() {
    git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}

# bash profile theme
export PS1="\[\e[1;37m\]parthnaik:\[\033[33;1m\]\w\[\033[m\]\$(parse_git_branch) \n$ "
export CLICOLOR=1
export LSCOLORS=GxFxCxDxBxegedabagaced

# firevault memory security
alias sleepsafe='sudo pmset -a destroyfvkeyonstandby 1 hibernatemode 25 standby 0 standbydelay 0'
alias sleepdefault='sudo pmset -a destroyfvkeyonstandby 0 hibernatemode 3 standby 1 standbydelay 10800'

# enable / disable captive portal
alias disablecaptiveportal='sudo defaults write /Library/Preferences/SystemConfiguration/com.apple.captive.control Active -bool false'
alias enablecaptiveportal='sudo defaults write /Library/Preferences/SystemConfiguration/com.apple.captive.control Active -bool true'

I was hoping someone more knowledgeable than me can help me understand what goes where since there seems to be some conflicting information online.

So far, from what I have read, here are the different suggestions I have seen:

  1. Copy pasting ~/.bash_profile to ~/.zshrc.
  2. Adding the following code at the bottom of ~/.zshrc:
if [ -f ~/.bash_profile ]; then 
    . ~/.bash_profile;
fi
  1. Creating a ~/.aliases file and a ~/.paths file and then sourcing/importing them to both ~/bash_profile as well as ~/.zshrc to maintain backward compatibility.

In addition to this, I have a .sh script that runs everyday automatically via command like:

sh script_name.sh

Should I change be changing this to use zsh like shown below? This should be the case if all .sh scripts with bash and zsh.

zsh script_name.sh

Looking for advice and best practises for migration although I know that any of the above would work in terms of functionality. Ideally, would like my theme, autocompletions and git branch settings (as shown in the ~/.bash_profile above) to work the same way as they do now.

For the theme, I know that there is a plugin called 'oh-my-zsh' available as well. Is this recommended to be installed?

Thank you for the help!

2
  • Don't know zsh best practices, but can tell you this: the export keyword is no longer necessary; your scripts will still run with sh, as that points to your default shell; your PS1 setup will need to be changed to zsh prompt expansions, though your parse_git_branch code and call in the PS1 will work as is... The PS1 is suggested to go into .zshrc, while the rest, I think, goes into .zprofile.
    – leanne
    Nov 20, 2019 at 23:52
  • Thank you @leanne. I did solve my problem and have posted the solution below. Nov 22, 2019 at 0:03

1 Answer 1

4

I decided to use the pure theme for zsh. My scripts work as normal, they just run via zsh now. Here is what my ~/.zshrc file looks like:

# PATHS AND ALIASES
# searches this directory for executables first
export PATH="/usr/local/bin:$PATH"

# jenv
export PATH="$HOME/.jenv/bin:$PATH"
eval "$(jenv init -)"

# rbenv
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"

# pyenv
export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init -)"

# nodenv
export PATH="$HOME/.nodenv/bin:$PATH"
eval "$(nodenv init -)"

# node-build-definitions
export NODE_BUILD_DEFINITIONS="/usr/local/opt/node-build-update-defs/share/node-build"

# firevault memory security
alias sleepsafe='sudo pmset -a destroyfvkeyonstandby 1 hibernatemode 25 standby 0 standbydelay 0'
alias sleepdefault='sudo pmset -a destroyfvkeyonstandby 0 hibernatemode 3 standby 1 standbydelay 10800'

# enable / disable captive portal
alias disablecaptiveportal='sudo defaults write /Library/Preferences/SystemConfiguration/com.apple.captive.control Active -bool false'
alias enablecaptiveportal='sudo defaults write /Library/Preferences/SystemConfiguration/com.apple.captive.control Active -bool true'

# CLI SETTINGS
# enable the default zsh completions
autoload -Uz compinit && compinit

# set colors for displaying directories and files when the ls command is used
export LSCOLORS='GxFxCxDxBxegedabagaced'
export CLICOLOR=1

# theme
fpath+=("$HOME/.zsh/pure")
autoload -U promptinit && promptinit
prompt pure

# change the path color
zstyle :prompt:pure:path color white
2
  • I thought ~/.bash_profile should go to what is now ~/.zprofile? Am I wrong? And if so, what is ~/.zprofile for then? Feb 26, 2020 at 23:45
  • 1
    You could place it there as well. There’s some differences between the 2 but in this case it will work the same. Feb 28, 2020 at 8:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .