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
That's it!
Configure Zsh
Minimal Configuration
To configure zsh, just populate ~/.zshrc
like this:
# enable the default zsh completions!
autoload -Uz compinit && compinit
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
After that, we can load the scripts in the ~/.zshrc
:
zstyle ':completion:*:*:git:*' script ~/.zsh/git-completion.bash
fpath=(~/.zsh $fpath)
Finally, remove the cache:
$ rm ~/.zcompdump
Define Aliases
My favorite and minimal aliases are:
alias ..='cd ..'
alias ...='cd ../..'
alias ls='ls -GwF'
alias ll='ls -alh'
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'
In the same way, to edit ~/.gitconfig
by the command gitconfig
, add the line below in the ~/.zshrc
:
alias gitconfig='code ~/.gitconfig'
Prettify the Console with Starship ð
Do you know starship?
TLDR, see my pretty console :)
I love this console! lol
Installation
$ brew install starship
And add the init script to the end of ~/.zshrc
:
eval "$(starship init zsh)"
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 = "ð "
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)
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!
zsh + ohmyzsh + powerlevel10k >
I too am a cat lover, basketball enthusiast, and struggling TypeScript developer ð.
Great tutorial!
What should I do if I already had
zsh
+ohmyzsh
installed?You can see the current default shell by running the command below:
If the result is
/bin/zsh
, this is the default macOS shell.So you need to change it:
And check your default shell has changed by running
echo ${SHELL}
:)How lucky for us who switched to Zsh many moons ago lol
Very nice. Thank you.
does one not need (the old) .bashrc anymore when using zsh? Everything goes to .zhrc right?
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 :)