DEV Community

Cover image for Getting started with oh-my-zsh
Dien Bui
Dien Bui

Posted on

Getting started with oh-my-zsh

Oh-my-zsh is an open source, community-driven framework for managing zsh and it is FREE. It has more than 180 optional plugin (rails, git, …), more than 120 theme and an auto-update tool to keep oh-my-zsh up-to-date.

In this tutorial, I will guide you to install it on your PC/laptop. The great thing about this is that you can customize your Shell and add plugins. Unlike the old Bash shell, which does not look attractive and can make it difficult for you to use when working with command-line a lot.


Pre-requisites

  • Linux and macOS because oh-my-zsh works best on Unix-based OS

  • UPDATE: WSL (Windows Subsystem for Linux) works with oh-my-zsh too.

  • zsh must be pre-installed. In OSX, it is already pre-installed. On Linux, you will need to type command in the Terminal to install:

  • curl or wget must be installed.

  • For Debian/Ubuntu:



sudo apt-get install zsh


Enter fullscreen mode Exit fullscreen mode
  • For Fedora:


sudo yum install zsh


Enter fullscreen mode Exit fullscreen mode

Install oh-my-zsh

  • curl


curl -L https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh | sh


Enter fullscreen mode Exit fullscreen mode
  • or wget


wget https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O - | sh


Enter fullscreen mode Exit fullscreen mode

Change default shell



chsh -s /bin/zsh


Enter fullscreen mode Exit fullscreen mode

Note: For some OSes, you may need to restart your computer for this to take effect.

Change Terminal theme

Now you have successfully installed oh-my-zsh. You will need to change the theme that is suitable for you, instead of using the default one. To change it, you will need to modify the .zshrc file



vim ~/.zshrc


Enter fullscreen mode Exit fullscreen mode

In this tutorial, I use vim text editor, you can use other text editor if you like. Next, locate this line in the file ZSH_THEME="robbyrussell".

Change the name robbyrussell to another name of another theme. You can have a look of all the available themes on this website .

Finally, just restart the Terminal and you will see the difference.

Auto-completion with Up

In Bash shell, you can use Ctrl + R and type keyword to auto-fill the most recent and matching command.

With oh-my-zsh, there is another way: you can type the starting words of the command you want and press Up button to cycle through the history.

For example, I am a Docker guy and use Docker daily and I want to view log of a container, I just simple type docker logs then press up, I will cycle me through:



docker logs -f --tail=1 cocoon-rest (first click)
docker logs -f --tail=1 cocoon-webapp (second click)


Enter fullscreen mode Exit fullscreen mode

After the second click, it shows the command I want, I hit Enter and then I can view the log of it.

I won’t explain about Docker in this post as it’s out of scope, but intend to write a Docker 101 post soon :) .

Auto-completion with Tab

In Bash shell, you can type keyword and press Tab to show list of matching commands, however you need to cycle through the list and remember the name you want and manually type further to complete.

With oh-my-zsh, things will get better, after pressing Tab the first time, you can press the second time to allow cycling through the list and choose the command you want, then it will automatically fill the rest of the words and finally just hit Enter and you are good to go. For example:

  1. Type doc and press Tab the first time

1_KTWHpqvCaLFL6KWC8U2wtw.png

  1. Press Tab the second time, then press Tab for Up, Down, Left, Right to cycle through

1_-b3VNwZivUqVcLFQKV0mRQ.png

Updating oh-my-zsh

It will update automatically, but if you want to do so manually just simply type this command in Terminal



omz update

Enter fullscreen mode Exit fullscreen mode




Read more

For more information about oh-my-zsh, you can have a look at this website.


Note: this post's origin is from my similar post on Medium with slight modification to update with latest changes of oh-my-zsh: https://dienbui.medium.com/using-oh-my-zsh-f65be6460d3f

Top comments (1)

Collapse
 
bosluk profile image
Can Berk

Nice guide for the beginners