I’m a big fan of the command line interface on my Ubuntu machine… I hate using my computer mouse! This motivated me to search for great tools to enhance my user experience on the CLI. I came across Oh-My-Zsh during my internship. Some friends convinced me to use the Zshell because of its simplicity and adjustability. As a bonus, the CLI is extendable with many plugins.
This is a list of its capabilities:
zshenv
, zprofile
, zshrc
, zlogin
, and zlogout
Add plugins: e.g. Git plugin with a huge list of useful Git aliases.This plugin shows the active branch and gives visual feedback about your Git status: - Green: branch if no changes occurred- Yellow with a circle icon: untracked files- Yellow with a plus icon: files ready to be committed
I’m performing this installation guide on my Ubuntu 16.04 Virtual Machine. To show you the underlying power of Oh-My-Zsh, I will install the Git plugin (Git-core). This plugin gives visual feedback about the Git status of a project.
Install prerequisite packages$ sudo apt install git-core zsh
Install Oh-My-Zsh from Robby Russell’s repository$ sh -c “$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
Install the Powerline font to spice up your CLI with icons$ sudo apt install fonts-powerline
Change theme from ‘robbyrussell’ to ‘agnoster’ for the legendary Oh-My-Zsh theme$ nano ~/.zshrc
ZSH_THEME
variable and change it:ZSH_THEME="agnoster"
I don’t like it that the theme shows my username and host. To get rid of this, we change the directory to $ cd ~/.oh-my-zsh/themes
Next we open the theme file for ‘agnoster’ in the editor $ nano agnoster.zsh-theme
build_prompt()
. Just comment out this line or remove it. At last, change the PROMPT
variable to $(build_prompt)
.
Agnoster theme configuration
To actually see the theme, you have to source your .zshrc
file like this: source ~/.zshrc
. If everything worked out fine, you should see something like the cover image!
Extra: Set zsh as our default shell. Execute this in your default shell, in most cases this will be bash. If you execute this command in zsh, it won’t change anything:$ chsh -s $(which zsh)
Note: If you use sudo
it will change the shell for root, but not for your working user.
All plugins listed on the plugins Github page are pre-installed with Oh-My-Zsh at ~/.oh-my-zsh/plugins
. Custom plugins can be installed at ~/.oh-my-zsh/custom/plugins
. To use a plugin, you can simply add it to the plugins list in your ~/.zshrc
file. Add wisely, as too many plugins slow down shell startup. Leave a blank between each plugin.
In this example, I’ve installed a useful plugin to give color highlighting to your man pages
. To be able to use the plugin, source your .zshrc
file: $ source ~/.zshrc
Colored Man Page of ls command
Another great plugin is syntax highlighting for your shell. Besides that, this plugin has the capability to verify the correctness of your command.
This plugin isn’t installed with Oh-My-Zsh. Navigate to ~/.oh-my-zsh/custom/plugins
and clone the code from Github into this folder:$ git clone https://github.com/zsh-users/zsh-syntax-highlighting
You will see a folder named zsh-syntax-highlighting
. This is the name that needs to be added to the plugins list.
You can also use zsh-autosuggestions
for command completion. It suggests commands based on your command history. Very useful! To select the proposed command, press the right arrow key.
Installation is the same as with zsh-syntax-highlighting
: $ git clone https://github.com/zsh-users/zsh-autosuggestionsAnd add zsh-autosuggestions
to the plugins list.
Oh-My-Zsh automatically remembers the 20 last directories you have visited. You can list the history chronologically with dirs -v
or just d
.
Normally, you can use cd +1
to go to the previous directory and so on. Oh-My-Zsh made this even more straightforward, now you can use the number of the entry in the directory history you want to visit… 1
.
alias
: List all aliases. You can pipe the output to grep
to search for a particular alias./
: cd /
~
: cd ~
...
: cd ../..
....
: cd ../../..
.....
: cd ../../../..
I think you get it, right?take test_folder
: Creates a folder named test_folder
and changes to itx
: Extract archive of types tar, bz2, rar, gz, tbz2, tgz, zip, Z, 7z
upgrade_oh_my_zsh
: Easy commando for upgrading your installationIt can happen the history file gets corrupt. Don’t ask me the specific details. Each time you launch a new terminal, you get this message:
zsh: corrupt history file /home/myusername/.zsh_history
Let’s fix it with the following commands. Make sure you are in the root of homefolder. The fc command lists, edits, or re-executes commands previously entered to a shell. The history command allows you to use words from previous command lines in the command line you are typing.
mv .zsh_history .zsh_history_badstrings .zsh_history_bad > .zsh_historyfc -R .zsh_history
Oh-My-Zsh is just awesome!
This article was made with the help of TheLedger.