Setup guide and introduction for Zsh and Oh-My-Zsh in Ubuntu(Include Powerlevel10k)
Let your shell get beautiful & easier to manipulate!
Co-Author: Y. S. Huang, a master’s student studying AIVC, likes open-source.
If you are interested, go to check my Github!
What are “Zsh” and “Oh My Zsh” ?
In Linux, the architecture of the operating system (OS) is above-mentioned. These different layers are in charge of data transmission between each other. The target of this article is to help you set up Zsh
, which is one of the mainstream in Shell layer.
But we have had Bash
for the default shell in our system, why do we need to use Zsh
rather than Bash
? Here are some outcoming features of Zsh
.
- You can make personal modifications to the appearance.
- Tons of plugins are ready for
Zsh
. - The most important one Auto-suggestions
Because setting-up Zsh
is too complicated, Oh-My-Zsh
becomes a great tool to help us accelerate setting.
Initial sequence of files in Zsh
In Linux, processes are sorted into interactive, non-interactive, login, non-login. Different kinds of processes may lead to different initial sequences.
interactive, non-interactive —whether controlled through a terminal session.
login, non-login — whether executed under your user ID.
/etc/zshenv
and~/.zshenv
These files will be the first to import to the shell. And they always initialed at the beginning in every progress. They will record $PATH
or $EDITOR
.
2. /etc/zprofile
and ~/.zprofile
When starting the login shell. The system will load zprofile
while logging, so non-login processes will skip this step.
3. /etc/zsh/zshrc
and ~/.zshrc
zshrc
is in charge of reading down personal settings like plugins and themes.
So, it is loaded only in interactive mode.
4. /etc/zsh/zlogin
and~/.zlogin
zlogin
functioned as zprofile
, but it is read after zprofile
. Therefore, non-login processes will skip this step.
5. /etc/zsh/zlogout
and ~/.zlogout
zlogout
is executed by turning off the terminal. So it usually read in the last place.
Let’s start setting up Zsh and Oh-My-Zsh!
In the beginning, enter echo $SHELL
to check the shell now. You should see the outcome below before using Zsh
.
/bin/bash
First of all, we need to download Zsh
, Git
, Curl
and Vim
with simple commend.
$ sudo apt update
$ sudo apt install zsh git curl vim
Next, we need to download Oh My Zsh through curl
, which is a common way to download files from websites.
$ sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
The following message will ask you whether change the shell to Zsh
. Press Y to confirm.
Looking for an existing zsh config...
Using the Oh My Zsh template file and adding it to ~/.zshrc.Time to change your default shell to zsh:
Do you want to change your default shell to zsh? [Y/n]
You can see the colorful string which means you have setup successfully!
Important operation for Zsh
The config file (a profile including the information to control the program) of Zsh
is call .zshrc
.We can edit the data in with Vim
to change the theme or add plugins. So make sure you can be skilled with it.
$ vim ~/.zshrc
Click this link downward to choose the theme you like.
Themes · ohmyzsh/ohmyzsh Wiki (github.com)
Just find the row ZSH_THEME= , and replace the “robbyrussell” with the theme name you prefer.
Set up Powerlevel10k
If you are not satisfied with official themes, using Powerlevel10k is an efficient way. In this section, we are going to modify the terminal on your own!
Download Powerlevel10k and add ZSH_THEME=powerlevel10k/powerlevel10k
on the row by vim.
$ git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k
$ vim ~/.zshrc
After editing .zshrc
, you should use the command below or just restart the terminal to activate the new theme.
source ~/.zshrc
When you reload the terminal, you might see something different on your screen. That is the setting progress of Powerlevel10k!
Look at the description and choose the following answer. It will help with adjusting some font errors and also making the terminal the style you like.
Meslo Nerd Font is officially recommended by powerlevel10k. Using this font may lead to fewer indication errors.
Install the one you like in your system.
And then, check Preference in the terminal and choose MekoLGS NF as a terminal font.
By far we had finished setting Powerlevel10k.
Usful plugins for Zsh
The most powerful feature of Oh-My-Zsh
is the various plugins. Here are some plugins I highly recommend for everyone. The stars in buckets mean how I recommend the plugin.
1. zsh-autosuggestions( ★ ★ ★)
Auto-suggestion plays a great role in programming. It can save tons of time spent on type repeat commends.
First, clone this plugin from Github.
$ git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
Use the method we mentioned before to edit .zshrc
. And add zsh-autosuggestions on plugins=() row like this.
Reload the terminal, you can notice something different. Try to type some commends, it will show the lastest commend you used correspond to the word you type.
2. zsh-syntax-highlighting( ★ ★ ★)
syntax-highlighting is also an indispensable plugin that everyone should install. It will show the wrong words in red.
$ git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
You should also add zsh-syntax-highlighting on plugins=() row.
3. dirhistory( ★ ★ ☆)
This plugin is so powerful to enter files. You can use Alt+left or right to move you backward or forward without cd
commend.
To install dirhistory, just add dirhistory on plugins=() row.