Zsh¶
1. Getting started¶
- Getting started with Zsh (by S. Kenlon)
- Zsh: The developer's dream shell (by Dispatch) (video)
- My ultimate Tmux, Zsh, and Neovim coding setup (by Dispatch) (video)
- Oh My Zsh wiki
- Oh My Zsh wiki: cheat sheet
2. Install¶
Install Zsh (Linux)¶
Install Z shell (Zsh). A guide on how to install Zsh can be found here.
First check: list the available valid login shells:
cat /etc/shells
Unlike Bash and other shells, Zsh requires initial configuration when you start it for the first time.
zsh
Set Zsh as the default shell for the current user:
chsh -s $(which zsh)
echo $SHELL.
Install Zsh (Windows)¶
Windows users have it harder. This blog post describes how Zsh can be installed on Windows in two different ways.
- Inside a "Windows Subsystem for Linux (WSL)" (recommended)
- Using "Git Bash" and "pacman"
From those two options, using the first (WSL) way appears less technical. WSL gives you a Linux system that essentially runs like another program in Windows. Within this Linux system, you can use the Zsh installation steps above.
Note: If you are using VS Code's terminal, it has "Git Bash" and "Powershell"; see VS Code - Terminal Shell Integration.
Install Oh My Zsh¶
Install Oh My Zsh
sh -c "$(wget -O- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
3. Customize Oh My Zsh with additional plugins¶
zsh-autosuggestions¶
- Clone the plugin's repository into oh-my-zsh's plugins directory
$ZSH_CUSTOM/plugins(by default~/.oh-my-zsh/custom/plugins):git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions - Activate the plugin by opening the file
~/.zshrc, scroll down to find the plugins variable, and add to the list of plugins:plugins=( # other plugins... zsh-autosuggestions ) - Restart zsh (such as by opening a new instance of your terminal emulator).
zsh-syntax-highlighting¶
- Clone the plugin's repository into oh-my-zsh's plugins directory
$ZSH_CUSTOM/plugins(by default~/.oh-my-zsh/custom/plugins):git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting - Activate the plugin by opening the file
~/.zshrc, scroll down to find the plugins variable, and add to the list of plugins:plugins=( # other plugins... zsh-syntax-highlighting) ) - Restart zsh (such as by opening a new instance of your terminal emulator).
zsh-autopair¶
- Clone the plugin's repository into oh-my-zsh's plugins directory
$ZSH_CUSTOM/plugins(by default~/.oh-my-zsh/custom/plugins):git clone https://github.com/hlissner/zsh-autopair ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autopair - Activate the plugin by opening the file
~/.zshrc, scroll down to find the plugins variable, and add to the list of plugins:plugins=( # other plugins... zsh-autopair ) - Restart zsh (such as by opening a new instance of your terminal emulator).
About login shells - What files get loaded when the shell starts?¶
Source: https://neovide.dev/faq.html#macos-login-shells
Traditionally, Unix shells use two main configuration files that are executed before a user can interact with the shell: a profile file and an rc file.
- Profile file: This file is typically executed once at login to set up the user's environment.
- RC file: This file is executed every time a new shell is created to configure the shell itself.
In the case of Zsh, the configuration files used are .zprofile and .zshrc.
Note hat Zsh has been the default shell on macOS since version 10.15.
Zsh - Bash differences¶
Unlike Zsh, Bash behaves differently. It only reads .bashrc if the shell
session is both interactive and non-login. This distinction might have been
overlooked when macOS transitioned from tcsh to bash in OSX 10.2 Jaguar,
leading developers to place their setup entirely in .profile since .bashrc
would rarely be executed, especially when starting a new terminal.
With the shift to Zsh as the default shell, both .zprofile and .zshrc are
executed when starting an interactive non-login shell.
