DEV Community

Yoshihide Shiono
Yoshihide Shiono

Posted on

A Guide for Upgrading macOS to Catalina and Migrating the Default Shell from Bash to Zsh

Index

  • From Bash to Zsh
  • Configure Zsh
    • Minimal Configuration
    • Enable Git Completion
    • Define Aliases
  • Prettify the Console with Starship 🚀

From Bash to Zsh

After upgrading macOS to Catalina (lol), the command below changes the default shell to zsh:

$ chsh -s /bin/zsh
Enter fullscreen mode Exit fullscreen mode

That's it!

Configure Zsh

Minimal Configuration

To configure zsh, just populate ~/.zshrc like this:

# enable the default zsh completions!
autoload -Uz compinit && compinit
Enter fullscreen mode Exit fullscreen mode

Enable Git Completion

To enable git completion, try commands below:

# make the `.zsh` directory
$ mkdir -p ~/.zsh
$ cd ~/.zsh

# download the scripts for completion
$ curl -o git-completion.bash https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash
$ curl -o _git https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.zsh
Enter fullscreen mode Exit fullscreen mode

After that, we can load the scripts in the ~/.zshrc:

zstyle ':completion:*:*:git:*' script ~/.zsh/git-completion.bash
fpath=(~/.zsh $fpath)
Enter fullscreen mode Exit fullscreen mode

Finally, remove the cache:

$ rm ~/.zcompdump
Enter fullscreen mode Exit fullscreen mode

Define Aliases

My favorite and minimal aliases are:

alias ..='cd ..'
alias ...='cd ../..'
alias ls='ls -GwF'
alias ll='ls -alh'
Enter fullscreen mode Exit fullscreen mode

Yes ll is not defined when using zsh.

And if we use VSCode, we can edit ~/.zshrc by running the command zshrc:

alias zshrc='code ~/.zshrc'
Enter fullscreen mode Exit fullscreen mode

In the same way, to edit ~/.gitconfig by the command gitconfig, add the line below in the ~/.zshrc:

alias gitconfig='code ~/.gitconfig'
Enter fullscreen mode Exit fullscreen mode

Prettify the Console with Starship 🚀

Do you know starship?

TLDR, see my pretty console :)

my pretty console image

I love this console! lol

Installation

$ brew install starship
Enter fullscreen mode Exit fullscreen mode

And add the init script to the end of ~/.zshrc:

eval "$(starship init zsh)"
Enter fullscreen mode Exit fullscreen mode

Configuration

For full information, please see the documentation.

My minimal configuration as a TypeScript developer, a cat lover and a basketball enthusiast is:

# in `~/.config/starship.toml`

[character]
symbol = "🐈💕"

[directory]
fish_style_pwd_dir_length = 10

[git_branch]
symbol = "🏀 "

[nodejs]
symbol = "⚡ "

[package]
symbol = "🎉 "
Enter fullscreen mode Exit fullscreen mode
symbol why or what
🐈💕 just so cute - nyaaan in Japanese / meow in English
🏀 master git branch
⚡ v12.11.1 nodejs version
🎉 v6.6.0 package version

Conclusion

No console, no developers :)

Top comments (9)

Collapse
 
davidxswang profile image
Davidxswang •

Thank you for this post! I met the problem a few days ago that I cannot use auto completion when I was using git, but it worked before. I searched a lot of places but didn't solve this problem perfectly, either prompting warning for me or prompting a lot of errors. Your post just solved it! Thank you!

Collapse
 
stephanie profile image
Stephanie Handsteiner •

zsh + ohmyzsh + powerlevel10k >

Collapse
 
pedroapfilho profile image
Pedro Filho •

What should I do if I already had zsh+ohmyzsh installed?

Collapse
 
saltyshiomix profile image
Yoshihide Shiono •

You can see the current default shell by running the command below:

$ echo ${SHELL}

If the result is /bin/zsh, this is the default macOS shell.

So you need to change it:

$ chsh -s /path/to/your/custom/zsh

And check your default shell has changed by running echo ${SHELL} :)

Collapse
 
codercatdev profile image
Alex Patterson •

I too am a cat lover, basketball enthusiast, and struggling TypeScript developer 🙀.

Great tutorial!

Collapse
 
walkingriver profile image
Michael D. Callaghan •

Very nice. Thank you.

Collapse
 
codenutt profile image
Jared •

How lucky for us who switched to Zsh many moons ago lol

Collapse
 
brando90 profile image
brando90 •

does one not need (the old) .bashrc anymore when using zsh? Everything goes to .zhrc right?

Collapse
 
saltyshiomix profile image
Yoshihide Shiono •

If you are using MacOS Catalina from the first, everything goes to zsh. Otherwise if you upgrade OS, we need change the default shell from bash to zsh :)