zsh config guide
Installation
sudo apt install zsh
Activate:
zsh
You will see this message:
This is the Z Shell configuration function for new users,
zsh-newuser-install.
You are seeing this message because you have no zsh startup files
(the files .zshenv, .zprofile, .zshrc, .zlogin in the directory
~). This function can help you with a few settings that should
make your use of the shell easier.
You can:
(q) Quit and do nothing. The function will be run again next time.
(0) Exit, creating the file ~/.zshrc containing just a comment.
That will prevent this function being run again.
(1) Continue to the main menu.
(2) Populate your ~/.zshrc with the configuration recommended
by the system administrator and exit (you will need to edit
the file by hand, if so desired).
--- Type one of the keys in parentheses ---
Press 1
to continue to the main menu:
Please pick one of the following options:
(1) Configure settings for history, i.e. command lines remembered
and saved by the shell. (Recommended.)
(2) Configure the new completion system. (Recommended.)
(3) Configure how keys behave when editing command lines. (Recommended.)
(4) Pick some of the more common shell options. These are simple "on"
or "off" switches controlling the shell's features.
(0) Exit, creating a blank ~/.zshrc file.
(a) Abort all settings and start from scratch. Note this will overwrite
any settings from zsh-newuser-install already in the startup file.
It will not alter any of your other settings, however.
(q) Quit and do nothing else. The function will be run again next time.
--- Type one of the keys in parentheses ---
Configure (1)
and (2)
, then press 0
to save and exit. You will see the following message and be taken to the prompt:
The function will not be run in future, but you can run
it yourself as follows:
autoload -Uz zsh-newuser-install
zsh-newuser-install -f
The code added to ~/.zshrc is marked by the lines
# Lines configured by zsh-newuser-install
# End of lines configured by zsh-newuser-install
You should not edit anything between these lines if you intend to
run zsh-newuser-install again. You may, however, edit any other part
of the file.
Change default shell to zsh
:
chsh -s $(which zsh)
Restart the terminal and check the default shell has been changed:
echo $SHELL
Install Oh My Zsh
Download the installation script:
wget https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh
Run the script:
chmod +x ./install.sh
./install.sh
Adjust .zshrc
to your likings. For example, you can uncomment the following two lines:
# DISABLE_AUTO_TITLE="true"
...
# COMPLETION_WAITING_DOTS="true"
Reload the zsh
config:
source ~/.zshrc
Switch to the agnoster theme
Open .zshrc
:
nano ~/.zshrc
Locate the ZSH_THEME
variable:
ZSH_THEME="robbyrussell"
Change it to agnoster
and save:
ZSH_THEME="agnoster"
(Optional) disable git branch information for agnoster
Start by opening the agnoster config file:
nano ~/.oh-my-zsh/themes/agnoster.zsh-theme
Comment out the prompt_git
line inside the function build_prompt() {...}
, then save and exit:
# prompt_git
Reload the zsh
config:
source ~/.zshrc
Install the Powerline fonts:
sudo apt install fonts-powerline
Update the font cache:
sudo fc-cache -vf
In the terminal preferences, change the dark blue color of the palette to #68A4F1
for more visible blue.
Plugins
Recommended plugins that works out-of-the-box with Oh My Zsh
timer
: displays command’s execution time
Recommended plugins that need to be installed
Install zsh-autosuggestions
for autosuggestions:
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
Install zsh-syntax-highlighting
for syntax highlighting:
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
Check the installed plugins:
cd $ZSH_CUSTOM/plugins
ls
Enable the plugins
Start by opening .zshrc
:
nano ~/.zshrc
Locate the plugins
variable:
plugins=(git)
Append the plugins to enable them. The plugins are space-separated inside the brackets.
plugins=(git timer zsh-autosuggestions zsh-syntax-highlighting)
Save, exit, and reload the zsh
config:
source ~/.zshrc
Reference
https://www.youtube.com/watch?v=gNP_ULriGN4
https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
https://github.com/agnoster/agnoster-zsh-theme
https://stackoverflow.com/questions/48535475/hiding-git-branch-information-in-oh-my-zsh
https://github.com/powerline/fonts
https://powerline.readthedocs.io/en/latest/installation/linux.html#fonts-installation
https://gabrieltanner.org/blog/customizing-terminal-using-ohmyzsh/
https://github.com/ohmyzsh/ohmyzsh/wiki/Plugins
Appendix A: Tips for using zsh-autosuggestions
Shortcuts
To accept the entire suggestion, press Right Arrow
.
To accept the next word, press Ctrl
+ Right Arrow.
Style
The ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE
variable controls the style of the autosuggestions. The default value is fg=8
.
To make the autosuggestions more visible, append the following to .zshrc
to set the foreground color to 7
:
# zsh-autosuggestions
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=7"
To choose from more colors, check the color chart at https://upload.wikimedia.org/wikipedia/commons/1/15/Xterm_256color_chart.svg.
Save, exit, and reload the zsh
config:
source ~/.zshrc
Appendix B: integrate existing conda into zsh
Switch to bash
:
bash
Perform a dry run of conda init
to check what will be modified:
conda init zsh -d
If satisfied, remove the -d
flag and run again:
conda init zsh
Restart the terminal to take effect.