My modified version of productive ZSH
The original Medium post is available here: Terminal can be much much more productive. The post is very extensive and worth reading, but I find it a bit too long. That's why I adapted it to my needs over time.
Install ZSH and set it as the default shell
Installing ZSH
$ sudo apt install zsh
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
zsh-common
Suggested packages:
zsh-doc
The following NEW packages will be installed:
zsh zsh-common
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 4794 kB of archives.
After this operation, 18.2 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 https://mirrors.edge.kernel.org/ubuntu jammy/main amd64 zsh-common all 5.8.1-1 [3985 kB]
Get:2 https://mirrors.edge.kernel.org/ubuntu jammy/main amd64 zsh amd64 5.8.1-1 [809 kB]
...
Set it as the default shell
$ sudo usermod -s /usr/bin/zsh vagrant
$ echo $?
0
Verify it is set correctly
$ getent passwd vagrant
vagrant:x:1000:1000::/home/vagrant:/usr/bin/zsh
Initial setup of ZSH
After the first login, follow the setup process offered by ZSH itself.
The resulting .zshrc looks like:
% cat .zshrc
# The following lines were added by compinstall
zstyle :compinstall filename '/home/vagrant/.zshrc'
autoload -Uz compinit
compinit
# End of lines added by compinstall
# Lines configured by zsh-newuser-install
HISTFILE=~/.zsh_histfile
HISTSIZE=100000
SAVEHIST=10000
# End of lines configured by zsh-newuser-install
Install Oh My Zsh
Oh My Zsh is an open source, community-driven framework for managing your zsh configuration. Its GitHub repository is Oh-My-Zsh.
% sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
Cloning Oh My Zsh...
remote: Enumerating objects: 1340, done.
remote: Counting objects: 100% (1340/1340), done.
remote: Compressing objects: 100% (1291/1291), done.
remote: Total 1340 (delta 27), reused 1153 (delta 25), pack-reused 0
Receiving objects: 100% (1340/1340), 1.99 MiB | 734.00 KiB/s, done.
Resolving deltas: 100% (27/27), done.
From https://github.com/ohmyzsh/ohmyzsh
* [new branch] master -> origin/master
Branch 'master' set up to track remote branch 'master' from 'origin'.
Already on 'master'
/home/vagrant
...
Add the $HOME/bin PATH environment variable
% cat ~/.zshrc
# If you come from bash you might have to change your $PATH.
export PATH=$HOME/bin:$PATH
# Path to your oh-my-zsh installation.
export ZSH="$HOME/.oh-my-zsh"
...
Setting the ZSH theme
I prefer powerlevel10k and will use it in my setup.
% git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k
Cloning into '/home/vagrant/.oh-my-zsh/custom/themes/powerlevel10k'...
remote: Enumerating objects: 92, done.
remote: Counting objects: 100% (92/92), done.
remote: Compressing objects: 100% (76/76), done.
remote: Total 92 (delta 17), reused 65 (delta 12), pack-reused 0
Receiving objects: 100% (92/92), 346.80 KiB | 1.53 MiB/s, done.
Resolving deltas: 100% (17/17), done.
Set the required variables in ~/.zshrc.
% vim ~/.zshrc
% grep ZSH_THEME ~/.zshrc
# ZSH_THEME="robbyrussell"
ZSH_THEME="powerlevel10k/powerlevel10k"
# Setting this variable when ZSH_THEME=random will cause zsh to load
# ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" )
Log out and log in again to start using Oh My ZSH and the new theme.
When you log in again, answer the few questions prompted at the start.
My preferred settings are:
- The lean style, so I answer
1to the question about the prompt style unicodecharacter set- The number of colors
256 - The 24h time format
- Two-line prompt
- Disconnected prompt
- No prompt frame
- Sparse prompt spacing
- Few icons
- Concise prompt flow
- Transient prompt
- Verbose prompt mode
If you are not happy with the current configuration, you can always start from scratch or change your ~/.p10k.zsh.
Add required plugins
I use only a few plugins. Some of them are part of Oh My Zsh, and some must be installed separately. If a plugin is not described as a separate installation, it is part of Oh My Zsh.
❯ grep -A10 plugin ~/.zshrc ✘ INT 8s 18:44:05
# Which plugins would you like to load?
# Standard plugins can be found in $ZSH/plugins/
# Custom plugins may be added to $ZSH_CUSTOM/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(
git
kubectl
zsh-syntax-highlighting
zsh-autosuggestions
)
source $ZSH/oh-my-zsh.sh
...
Install the plugin zsh-syntax-highlighting
This plugin is installed according to its Installation instructions.
❯ git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
Cloning into '/home/vagrant/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting'...
remote: Enumerating objects: 7041, done.
remote: Counting objects: 100% (128/128), done.
remote: Compressing objects: 100% (71/71), done.
remote: Total 7041 (delta 63), reused 84 (delta 51), pack-reused 6913
Receiving objects: 100% (7041/7041), 1.52 MiB | 2.19 MiB/s, done.
Resolving deltas: 100% (4738/4738), done.
Install the plugin zsh-autosuggestions
❯ git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
Cloning into '/home/vagrant/.oh-my-zsh/custom/plugins/zsh-autosuggestions'...
remote: Enumerating objects: 2460, done.
remote: Counting objects: 100% (75/75), done.
remote: Compressing objects: 100% (52/52), done.
remote: Total 2460 (delta 36), reused 50 (delta 21), pack-reused 2385
Receiving objects: 100% (2460/2460), 571.83 KiB | 984.00 KiB/s, done.
Resolving deltas: 100% (1567/1567), done.
Log out and log in again to start using the new plugins.
TLDR
Warning
This script is tested on Ubuntu 22.04.
If you want to save time and do not need to know what happens under the hood, run the command below and wait until the script finishes. Then reboot the machine, and you are ready to go.
wget -qO- https://raw.githubusercontent.com/tbosnjak/bootstrap-working-environment/main/bootstrap.sh | sh