ZSH Cheatsheet
Pretty up your shell with zsh.
Add Zsh to MacOSX
MacOS comes with zsh installed by default as the default shell starting with macOS Catalina (10.15). However, if you need to install a newer version of zsh or switch to it on an older version of macOS, here’s how you can do it:
Check if zsh is Already Installed
In your Terminal, type:
1
zsh --version
If a version of zsh is listed, it’s already installed. You can switch to it by changing your default shell. If you need a newer version, you can install it with Homebrew.
Change Your Default Shell to zsh
Add the new zsh path to the list of allowed shells by editing the /etc/shells
file:
1
sudo nano /etc/shells
Add the path from the Homebrew installation (typically /opt/homebrew/bin/zsh on Apple Silicon or /usr/local/bin/zsh on Intel Macs) to the end of the file, then save and exit.
Set zsh as your default shell:
1
chsh -s /bin/zsh
Restart your Terminal for the changes to take effect.
Verify the Default Shell
To confirm zsh is now your default shell, type:
1
echo $SHELL
It should display the path to zsh, indicating it’s now your default shell.
You’re all set! Now you can configure zsh with additional plugins, themes, or configurations.
Zshrc Config file
All your config settings for zsh live in the .zshrc config file. Store it in your users .config/.zshrc
directory
Create symlink for .config
location
1
ln -s ~/.config/.zshrc ~/.zshrc
Install a ZSH theme or skin
To install a Zsh theme or “skin,” you’ll typically be working with a popular framework like Oh My Zsh, which makes theme management much easier. Here’s a step-by-step guide:
1. Install Oh My Zsh (if you haven’t already)
Oh My Zsh is a framework that simplifies the customization of Zsh, including adding themes.
1
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
This command will overwrite your existing .zshrc
file and copy your old file to a .zshrc@pre-oh-my-zsh
2. Choose a Theme
Oh My Zsh includes many themes by default. You can browse them here. The Agnoster
and Powerlevel10k
themes are popular choices.
To install Powerlevel10k
, for example:
1
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k
Install with homebrew
Install with homebrew for a straight forward.
1
2
brew install powerlevel10k
echo "source $(brew --prefix)/share/powerlevel10k/powerlevel10k.zsh-theme" >>~/.zshrc
3. Set the Theme in Your .zshrc File
Open the .zshrc
file in your home directory.
1
nano ~/.zshrc
Find the line:
1
ZSH_THEME="robbyrussell"
Replace “robbyrussell” with the name of the theme you want to use. For Powerlevel10k, it should look like this:
1
ZSH_THEME="powerlevel10k/powerlevel10k"
- Apply the Changes
After saving the .zshrc file, apply the changes:
1
source ~/.zshrc
- Configure Powerlevel10k (if applicable)
If you’re using Powerlevel10k, it will launch a configuration wizard the first time you load it. Follow the prompts to customize your theme. Tips:
Fonts: Some themes, especially Powerlevel10k, require special fonts to display icons correctly. Nerd Fonts are commonly used. Plugins: Zsh has many plugins that can add functionality. You can enable plugins in your .zshrc file by adding them to the plugins=() line.
That’s it! You should now have a Zsh theme applied.
Troubleshooting
When changing shell i get chsh: WARNING: shell '/usr/local/opt/zsh' is not a regular file.
The warning you’re seeing indicates that the specified path (/usr/local/opt/zsh) isn’t recognized as a valid shell path by your system. This could happen if the symbolic link or installation path isn’t pointing directly to the zsh executable.
Keyboard Navigation commands
CTRL + A
Move to the beginning of the line
CTRL + E
Move to the end of the line
CTRL + [left arrow]
Move one word backward (on some systems this is ALT + B)
CTRL + [right arrow]
Move one word forward (on some systems this is ALT + F)
CTRL + U
(bash) Clear the characters on the line before the current cursor position
CTRL + U
(zsh) If you’re using the zsh, this will clear the entire line
CTRL + K
Clear the characters on the line after the current cursor position
ESC + [backspace]
Delete the word in front of the cursor
CTRL + W
Delete the word in front of the cursor
ALT + D
Delete the word after the cursor
CTRL + R
Search history
CTRL + G
Escape from search mode
CTRL + _
Undo the last change
CTRL + L
Clear screen
CTRL + S
Stop output to screen
CTRL + Q
Re-enable screen output
CTRL + C
Terminate/kill current foreground process
CTRL + Z
Suspend/stop current foreground process
Command Action
!!
Execute last command in history
!abc
Execute last command in history beginning with abc
!abc:p
Print last command in history beginning with abc
http://www.geekmind.net/2011/01/shortcuts-to-improve-your-bash-zsh.html