Skip to main content

Installing Oh-My-Zsh on Ubuntu 20.04

Central, Hong Kong

In order for Oh-My-Zsh to work on the system ,zsh need to be installed.

Install ZSH

apt install wget curl git -y
apt install zsh

To check installed version of ZSH:

zsh --version
zsh 5.8 (x86_64-ubuntu-linux-gnu)

Changing your default shell to zsh:

usermod -s $(which zsh) root
chsh -s $(which zsh)

Install Oh-my-Zsh

Clone the repo:

sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

or

sh -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"

The Oh-my-Zsh configuration files are located under $HOME/.oh-my-zsh/ directory. Note that ZSH config file is $HOME/.zshrc.

Theming

nano $HOME/.zshrc

robbyrussel is the default theme for ZSH:

# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
ZSH_THEME="robbyrussell"
...

To change the theme, simply get the name of the theme from $HOME/.oh-my-zsh/themes/ and replace it. For example, to change the themes to bureau theme, $HOME/.oh-my-zsh/themes/bureau.zsh-theme:

ZSH_THEME="bureau"

Reload the ~/.zshrc to effect the changes everytime you make changes.

source ~/.zshrc

Enable Oh-My-Zsh Plugins

Plugins are stored under ~/.oh-my-zsh/plugins. Plugins can be enabled by defining them under the plugins section on ~/.zshrc config file:

plugins=(git docker-compose docker ansible vagrant sudo)

Save and exit the shell. Then source ~/.zshrc for the changes to take effect.

source ~/.zshrc

External Plugins

Clone the desired plugin - e.g. zsh-autocomplete and add it to your .zshrc file:

cd /home/ubuntu
git clone https://github.com/marlonrichert/zsh-autocomplete.git
nano .zshrc

Add the following to your .zshrc file:

source /home/ubuntu/zsh-autocomplete/zsh-autocomplete.zsh

Adding EXA

exa is a modern replacement for the venerable file-listing command-line program ls that ships with Unix and Linux operating systems, giving it more features and better defaults. It uses colours to distinguish file types and metadata. It knows about symlinks, extended attributes, and Git. And it’s small, fast, and just one single binary.

apt install exa

Adding a shortcut in nano .bashrc:

alias dir='exa -abghHlS --tree'

Command-line options

exa’s options are almost, but not quite, entirely unlike ls’s.

Display options

-1, --onelinedisplay one entry per line
-G, --griddisplay entries as a grid (default)
-l, --longdisplay extended details and attributes
-R, --recurserecurse into directories
-T, --treerecurse into directories as a tree
-x, --acrosssort the grid across, rather than downwards
-F, --classifydisplay type indicator by file names
--colo[u]rwhen to use terminal colours
--colo[u]r-scalehighlight levels of file sizes distinctly
--iconsdisplay icons

Filtering options

-a, --allshow hidden and 'dot' files
-d, --list-dirslist directories like regular files
-L, --level=(depth)limit the depth of recursion
-r, --reversereverse the sort order
-s, --sort=(field)which field to sort by
--group-directories-firstlist directories before other files
-D, --only-dirslist only directories
--git-ignoreignore files mentioned in .gitignore
-I, --ignore-glob=(globs)glob patterns (pipe-separated) of files to ignore

Pass the --all option twice to also show the . and .. directories.

Long view options

These options are available when running with --long (-l)

-b, --binarylist file sizes with binary prefixes
-B, --byteslist file sizes in bytes, without any prefixes
-g, --grouplist each file’s group
-h, --headeradd a header row to each column
-H, --linkslist each file’s number of hard links
-i, --inodelist each file’s inode number
-m, --modifieduse the modified timestamp field
-S, --blockslist each file’s number of file system blocks
-t, --time=(field)which timestamp field to use
-u, --accesseduse the accessed timestamp field
-U, --createduse the created timestamp field
-@, --extendedlist each file’s extended attributes and sizes
--changeduse the changed timestamp field
--gitlist each file’s Git status, if tracked or ignored
--time-stylehow to format timestamps
--no-permissionssuppress the permissions field
--no-filesizesuppress the filesize field
--no-usersuppress the user field
--no-timesuppress the time field

Some of the options accept parameters

  • Valid --color options are always, automatic, and never.
  • Valid sort fields are accessed, changed, created, extension, Extension, inode, modified, name, Name, size, type, and none. Fields starting with a capital letter sort uppercase before lowercase. The modified field has the aliases date, time, and newest, while its reverse has the aliases age and oldest.
  • Valid time fields are modified, changed, accessed, and created.
  • Valid time styles are default, iso, long-iso, and full-iso.

Manual Update Oh-My-ZSH

rm -rf ~/.oh-my-zsh && git clone https://github.com/ohmyzsh/ohmyzsh.git ~/.oh-my-zsh