Extend the functionality of Zsh with themes and plug-ins installed by Oh My Zsh.

In my previous article, I showed you how to install and use z-Shell (Zsh). The most exciting thing about Zsh for some users is that it can install themes. Zsh themes are easy to install, partly because there is a very active community designing themes for Z-Shell and partly because of the Oh My Zsh project. This makes installing themes a breeze.

Theme changes can grab your attention right away, so if you install Zsh and replace the default Shell with Zsh and you don’t like the way your Shell’s default theme looks, you can immediately replace the 100 + themes that come with Oh My Zsh. Oh My Zsh not only has a large number of beautiful themes, but also hundreds of plug-ins that extend Zsh’s capabilities.

Install Oh My Zsh

The Oh My Zsh website recommends that you use a script to install the package with Internet access. While the Oh My Zsh project is almost convincing, blindly running a script on your computer is bad advice. If you want to run the script, you can download it, see what it does, and then run it once you’re sure you know what it does.

If you download the script and read it, you’ll see that the installation process is just three steps:

1. Clone OH-my-ZSH

Step 1: Clone oh-my-zsh library to ~/. Oh-my-zsh directory:

% git clone http://github.com/robbyrussell/oh-my-zsh ~/.oh-my-zsh
Copy the code

2. Switch the configuration file

Next, back up your existing.zshrc files and move the oh-my-zsh configuration files to this location. Both steps can be done in one step, as long as your mv command supports the -b option.

% mv -b \
~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc
Copy the code

3. Edit the configuration file

By default, the configuration file that comes with Oh My Zsh is very rudimentary. If you want to merge your own ~/.zshrc files into the.oh-my-zsh configuration file. You can use the cat command to add your old configuration file to the end of the new one.

% cat ~/.zshrc~ >> ~/.zshrc
Copy the code

Take a look at the default configuration file and some of the options it provides. Open the ~/.zshrc file with your favorite editor. This file is very well commented. That’s a really good way to see it.

For example, you can change the location of the.oh-my-zsh directory. It is installed in your home directory by default. However, according to the modern Linux specification as defined by Free Desktop. This directory should be placed in ~/.local/share. You can change it in the configuration file. As follows:

# Path to your oh-my-zsh installation.
export ZSH=$HOME/.local/share/oh-my-zsh
Copy the code

Then move the.oh-my-zsh directory to your newly configured directory:

% mv ~/.oh-my-zsh $HOME/.local/share/oh-my-zsh
Copy the code

If you’re using MacOS, this directory can be a bit ambiguous, but the best place to do it is probably at $HOME/Library/Application\ Support.

Restart Zsh

After editing the configuration file, you must restart your Shell. Before you do that, you have to make sure that anything you do is done correctly. For example, after you change the path to the.oh-my-zsh directory. Don’t forget to move the directory to the new location. If you don’t want to restart your Shell. You can use the source command to validate your configuration file.

% sourceThose who qualify can go onto university. ~/.zshrc ➜. Oh-my-zsh git:(master) qualifyCopy the code

You can ignore any warnings about missing update files; They will parse again on reboot.

Change your theme

After installing oH-my-Zsh. You can set your Zsh theme to RobbyRussell, which is the theme of the project’s maintainer. The change to this theme is very minor, just changing the color of the prompt.

You can see all installed themes by listing all files in the.oh-my-zsh directory:

➜. Oh-my-zsh git:(master) qualify ls ~/. Local /share/oh-my-zsh/themes 3den.zsh-theme adben.zsh-theme af-magic.zsh-theme afowler.zsh-theme agnoster.zsh-theme [...]Copy the code

To see what it looks like before switching themes, check out the Oh My Zsh wiki page. To see more topics, check out the external Topics Wiki page.

Most themes are very easy to install and use, just change the configuration options in the.zshrc file and reload the configuration file.

➜ ~ sed - I's/_THEME=\"robbyrussel\"/_THEME=\"linuxonly\"/g'~ /.zshrc ➜ ~source~/.zshrc seth@darkstar:pts/0-> / home/skenlon ➜ (0)Copy the code

Other topics may require some additional configuration. For example, in order to use the Agnoster theme, you must first install the Powerline font. This is an open source font, and if you use Linux, this font probably exists in your software library. Use the following command to install this font:

➜ ~ sudo dnf install powerline-fonts
Copy the code

Change your theme in the configuration file:

➜ ~ sed - I's/_THEME=\"linuxonly\"/_THEME=\"agnoster\"/g' ~/.zshrc
Copy the code

Restart your Sehll (a simple source command will not work). Once you restart, you can see the new theme:

agnoster theme

Installing a plug-in

Oh My Zsh has over 200 plugins, which you can see in.oh-my-zsh/plugins. Each extension directory has a README file that explains what the plug-in does.

Some plug-ins are fairly simple. For example, DNF, Ubuntu, Brew, and Macports plug-ins are just aliases defined to simplify interaction with DNF, Apt, Homebres, and MACports.

Others are more complex, and git plug-ins are activated by default. When your directory is a Git repository, this extension updates your Shell prompt to show the current branch and whether there are unmerged changes.

To enable this extension, you can add this extension to your configuration file ~/.zshrc. For example, you can add the DNF and Pass plugins and change them as follows:

plugins=(git dnf pass)
Copy the code

Save the changes and restart your Shell.

% source ~/.zshrc
Copy the code

This extension is now available. You can test this by using an alias provided by DNF:

% dnfs fop
====== Name Exactly Matched: fop ======
fop.noarch : XSL-driven print formatter
Copy the code

Different plug-ins do different things, so you can install one or two plug-ins at a time to help you learn new features and functions.

compatibility

Some Oh My Zsh plug-ins have generality. If you see a plug-in that claims to be Bash compatible, it can be used in your own Bash. Other plug-ins require specific functionality provided by Zsh. Therefore, not all of them work. But you can add other plug-ins, such as DNF, Ubuntu, Firewalld, and others. You can use Source to validate your selection. Such as:

if [ -d $HOME/.local/share/oh-my-zsh/plugins ]; then
        source $HOME/.local/share/oh-my-zsh/plugins/dnf/dnf.plugin.zsh
fi
Copy the code

Select or deselect Zsh

Z-shell’s built-in capabilities and its community-contributed extensions are powerful. You can use it as your main Shell, or you can try it out when you’re having fun. It depends on what you like.

Let us know what your favorite themes and extensions are in the comments below!


Via: opensource.com/article/19/…

By Seth Kenlon, lujun9972

This article is originally compiled by LCTT and released in Linux China