Oh-My-Zsh + Powerlevel10k: Zsh One-Click Configuration Script
This article utilizes Ubuntu & Termius, run the configuration script here.
Why Use Zsh?
- Aesthetic Shell themes and code highlighting.
- Enhanced code prompts and auto-completion compared to Bash.
- Support for a variety of plugins and themes.
Oh-My-Zsh
Given the wealth of plugins and themes in the Zsh ecosystem, Oh-My-Zsh serves as an out-of-the-box tool for managing plugins and themes, simplifying Zsh configuration.
Here's the list of readily available themes and plugins on GitHub:
However, these lists lack succinct descriptions. Many plugins are mainly used by developers and may not be of significant use. One must navigate through the links, wasting time. Hence, this list is more suitable for users interested in extensive exploration, particularly those seeking alias plugins. For regular users, the recommended plugins and themes suffice.
Moreover, numerous Zsh plugins and themes are not integrated into Oh-My-Zsh, such as Powerlevel10k, zsh-autosuggestions, requiring downloads from the respective GitHub repositories to be used in Zsh.
Plugins
There was a time when I didn't care about alias plugins when I didn't use the CLI frequently, and later I even needed to actively add aliases that weren't in the plugins.
The
thefuck
plugin is incompatible withsudo
since they both utilize theDouble ESC
shortcut.
Name | Oh-My-Zsh | Priority | Description |
---|---|---|---|
zsh-syntax-highlighting | ❌ | High | Supports code highlighting in Zsh terminal. |
zsh-autosuggestions | ❌ | High | Supports suggestions for Zsh terminal code completion. |
you-should-use | ✅ | High | Gives a tip when any command alias is available. |
git | ✅ | Medium | Lots of git aliases to lighten the git workload. |
zsh-history-substring-search | ❌ | Medium | Supports searching for history commands using keyword with up/down arrow keys. |
thefuck | ❌ | Medium | Press ESC twice to fix the last wrong command (e.g. add sudo ). |
colored-man-pages | ✅ | Medium | Syntax coloring for man help manual. |
debain | ✅ | Low | Some useful apt aliases. |
extract | ✅ | Low | Command x to extract various types of compressed files. |
autojump | ❌ | Low | Command j to automatically jump directories based on history. |
jsontools | ✅ | Low | Command pp_json to format JSON inputs. |
nvm | ✅ | Low | Auto reads the .nvmrc file in the directory to switch node version. |
Theme
The only recommended theme is Powerlevel10k. No other Zsh theme is suggested due to Powerlevel10k's succinct and elegant design.
P10K is presently the most commonly used theme for Zsh and is not included in Oh-My-Zsh default configuration. This underlines Powerlevel10k's excellence and popularity.
Powerlevel10k is a Zsh theme that emphasizes speed, flexibility, and out-of-the-box experience.
The Powerlevel10k theme offers multiple customizable options. Upon its initial installation or using the p10k configure
command, prompts appear for configuring the display, such as whether to show Unicode characters or gaps between multiple commands.
In order to realize the full potential of the Powerlevel10k theme, please follow the guide on Github to install the 'MesloLGS NF' font and set the terminal's font to 'MesloLGS NF', as many terminal default fonts cannot support the beautiful characters used by Powerlevel10k.
Zsh & Bash
Linux users must be aware of the differences between Zsh and Bash to avoid pitfalls:
- Zsh is compatible with most Bash syntax but lacks compatibility with some Bash file wildcards, specifically the use of
*
. - Zsh offers additional syntax extensions absent in Bash. Given the current prevalence of Bash in default Linux installations, it is advisable not to use Zsh extended syntax. Shell scripts should also utilize
#!/bin/bash
to ensure compatibility.
Configure Script
Specific Things To Do
Zsh configuration entails three actions:
- Installing common plugins and the Powerlevel10k theme.
- Moving
.zcompdump-*
files to the$ZSH/cache
directory. - Adding configurations to all new users through the
/etc/skel/
directory.
Regarding the second action, Zsh saves files used to expedite command completion in the format below, which defaults to the $HOME
directory:
-rw-r--r-- 1 aiktb aiktb 49K May 15 11:13 .zcompdump
-rw-r--r-- 1 aiktb aiktb 50K May 15 11:13 .zcompdump-shiro-5.8.1
-r--r--r-- 1 aiktb aiktb 115K May 15 11:13 .zcompdump-shiro-5.8.1.zwc
This format is undoubtedly unsightly and requires a configuration directory change. The solution for this can be found on StackOverflow.
Regarding the third action, files in the /etc/skel/
directory are automatically copied to the corresponding home
directory during the creation of a new Linux user, sparing the hassle of reconfiguring Zsh for each user.
One-Click Configuration Script
It is recommended to use the following command to download my one-click configuration script:
curl -sL https://raw.githubusercontent.com/aiktb/dotzsh/master/zsh.sh | bash && zsh
The code below efficiently accomplishes the aforementioned three tasks. Linux users employing the apt package manager can use this script directly, while users of other package managers may need to modify the code accordingly.
#!/bin/bash
sudo apt install zsh -y
# Install oh-my-zsh.
0>/dev/null sh -c "$(wget -O- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
ZSH_CUSTOM="$HOME/.oh-my-zsh/custom"
export ZSH_CUSTOM
# Configure plugins.
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git "${ZSH_CUSTOM}"/plugins/zsh-syntax-highlighting
git clone https://github.com/zsh-users/zsh-autosuggestions.git "${ZSH_CUSTOM}"/plugins/zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-history-substring-search "${ZSH_CUSTOM}"/plugins/zsh-history-substring-search
sudo apt install thefuck autojump -y
sed -i 's/^plugins=.*/plugins=(git\n extract\n thefuck\n autojump\n jsontools\n colored-man-pages\n zsh-autosuggestions\n zsh-syntax-highlighting\n zsh-history-substring-search\n you-should-use\n nvm\n debian)/g' ~/.zshrc
# Enable nvm plugin feature to automatically read `.nvmrc` to toggle node version.
sed -i "1s/^/zstyle ':omz:plugins:nvm' autoload yes\n/" ~/.zshrc
# Install powerlevel10k and configure it.
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git "${ZSH_CUSTOM}"/themes/powerlevel10k
sed -i 's/^ZSH_THEME=.*/ZSH_THEME="powerlevel10k\/powerlevel10k"/g' ~/.zshrc
# Move ".zcompdump-*" file to "$ZSH/cache" directory.
sed -i -e '/source \$ZSH\/oh-my-zsh.sh/i export ZSH_COMPDUMP=\$ZSH\/cache\/.zcompdump-\$HOST' ~/.zshrc
# Configure the default ZSH configuration for new users.
sudo cp ~/.zshrc /etc/skel/
sudo cp ~/.p10k.zsh /etc/skel/
sudo cp -r ~/.oh-my-zsh /etc/skel/
sudo chmod -R 755 /etc/skel/
sudo chown -R root:root /etc/skel/
Many Zsh plugin installation documents utilize the following Zsh syntax extension. Please refrain from using this in Bash:
${ZSH_CUSTOM:-~/.oh-my-zsh/custom}
Further Reading
Termius
All demo images in this article were executed using Termius, which, as you can see, is a very nice terminal!
Termius is currently included in the GitHub Student Developer Pack, which is free for one year for any certified student!
Httpie
Another Shell Tool: httpie, with a detailed documentation.
In brief, it serves as an alternative to curl
, providing highlighted outputs and automatic JSON formatting for commands using http
and https
.
sudo apt install httpie