Oh my Zsh, a cool command line extension tool on Linux

Time:2021-1-26

Oh my Zsh is a community driven command-line tool. As its home page says, oh my Zsh is a lifestyle. Based on Zsh command line, it provides theme configuration, plug-in mechanism and built-in convenient operation. Give us a new way to use the command line.
2015118111953669.jpg (952×461)

What is oh my Zsh
Oh my Zsh is a very interesting name. It is an extension tool set based on Zsh command line and provides rich extension functions. Oh my Zsh has a clear definition on its home page: http://ohmyz.sh

As for Zsh, it’s a command line program. The bash command line is used by default on our MAC system, and Zsh is another command line environment. You can learn about Zsh on its official website http://www.zsh.org/

We can enter this command in the command line to check whether the Zsh command line is installed on our computer

Copy code

The code is as follows:

zsh –version

If it is installed, this command will output the current version number of Zsh. After confirming that Zsh has been installed, we can continue to install oh my Zsh.

Oh my Zsh is nothing
When it comes to command-line tools, what’s our first feeling? Oh my Zsh?
2015118112043550.png (682×378)

Yeah.. Oh my Zsh is only a packaging framework for the configuration of the Zsh command line environment, but it does not provide a command line window, let alone an independent app.

The command line interface in the figure above can be a terminal program of the MAC system, or a command line program of a third party, such as iterm.

In short, oh my Zsh is not a replacement for a command-line tool, but a complement to them. You can use oh my Zsh with iterm, so you can get the convenient features of oh my Zsh command line environment, and also use the operation support of command line GUI tools provided by iterm.

As the home page of oh my Zsh says, “when you use these cool command line tools, people will come to your computer and praise your command line. Welcome a piece of praise. “

Install oh my Zsh
We understand the general situation of oh my Zsh, so let’s start the installation~

The installation method of oh my Zsh is very simple. There is a very clear description on its home page: http://ohmyz.sh

It can be installed by curl or WGet with one command.

Curl mode:

Copy code

The code is as follows:

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

WGet mode:

Copy code

The code is as follows:

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

The output during installation is as follows:

Copy code

The code is as follows:

Cloning Oh My Zsh…
Cloning into ‘/Users/icafe/.oh-my-zsh’…
remote: Counting objects: 712, done.
remote: Compressing objects: 100% (584/584), done.
remote: Total 712 (delta 15), reused 522 (delta 4), pack-reused 0
Receiving objects: 100% (712/712), 443.58 KiB | 27.00 KiB/s, done.
Resolving deltas: 100% (15/15), done.
Checking connectivity… done.
Looking for an existing zsh config…
Using the Oh My Zsh template file and adding it to ~/.zshrc
Copying your current PATH and adding it to the end of ~/.zshrc for you.
Time to change your default shell to zsh!
__ __
____ / /_ ____ ___ __ __ ____ _____/ /_
/ __ \/ __ \ / __ `__ \/ / / / /_ / / ___/ __ \
/ /_/ / / / / / / / / / / /_/ / / /_(__ ) / / /
\____/_/ /_/ /_/ /_/ /_/\__, / /___/____/_/ /_/
/____/ ….is now installed!
Please look over the ~/.zshrc file to select plugins, themes, and options.
p.s. Follow us at https://twitter.com/ohmyzsh.
p.p.s. Get stickers and t-shirts at http://shop.planetargon.com.

Here, oh my Zsh is installed successfully. Now you can see that our command line prompt looks like this:

2015118112117432.png (109×19)
set up themes
After the installation, we can use it. Let’s make a simple configuration first.

Oh my Zsh provides many theme styles. We can set the theme styles according to our preferences. The theme configuration can be seen in ~ /. Zshrc file. Open this file with a familiar editor and you can find this item:

Copy code

The code is as follows:

ZSH_THEME=”robbyrussel”

As you can see, the theme we use by default is called robbyrussel. Its display effect is like this:
2015118112214997.png (500×272)

Oh my Zsh comes with some default themes by default, which are stored in ~ /. Oh my Zsh / themes directory. We can look at these topics:

Copy code

The code is as follows:

themes git:(master) ls

3den.zsh-theme                essembeh.zsh-theme            junkfood.zsh-theme            rgm.zsh-theme
Soliah.zsh-theme              evan.zsh-theme                kafeitu.zsh-theme             risto.zsh-theme
adben.zsh-theme               example.zsh-theme             kardan.zsh-theme              rixius.zsh-theme
af-magic.zsh-theme            fino-time.zsh-theme           kennethreitz.zsh-theme        rkj-repos.zsh-theme
afowler.zsh-theme             fino.zsh-theme                kiwi.zsh-theme                rkj.zsh-theme
agnoster.zsh-theme            fishy.zsh-theme               kolo.zsh-theme                robbyrussell.zsh-theme
alanpeabody.zsh-theme         flazz.zsh-theme               kphoen.zsh-theme              sammy.zsh-theme
amuse.zsh-theme               fletcherm.zsh-theme           lambda.zsh-theme              simonoff.zsh-theme
apple.zsh-theme               fox.zsh-theme                 linuxonly.zsh-theme           simple.zsh-theme
arrow.zsh-theme               frisk.zsh-theme               lukerandall.zsh-theme         skaro.zsh-theme
….
Well, there are quite a number of default themes. This is the power of community driving, which can be reflected from the logo of oh my Zsh~
2015118112232952.png (337×208)

So many topics can satisfy your various preferences. We just need to configure the required topics in the. / zshrc file. For example, we want to use lambda.zsh -For theme, we only need to configure it as follows:

Copy code

The code is as follows:

ZSH_THEME=”lambda”

Then save the file and open a new command line window to see the effect. So how can we quickly find out which topics we like? We can also set them like this:

Copy code

The code is as follows:

ZSH_THEME=”random”

We set the theme to random, so that each time we open a command line window, we will randomly select one of the default themes. In this way, if we like the current topic, we can directly use the echo command to output the name of the current topic

Copy code

The code is as follows:

echo $ZSH_THEME

Then set it to the configuration file.
Quick selection of directories and files
Now that we have understood the subject, we are going on. We use another command line environment, obviously not only to use more theme style, but also to make it more convenient. So, let’s continue to take a look at the convenient operation provided by oh my Zsh.

When we use command-line tools to switch between directory and file through CD like commands, one of the pain points is that we must first check the directory structure and file name. For example, if we want to use the CD command to enter a directory, we must first know the name of the directory. This is not used to GUI tools like finder. In Bash, we usually use the LS command to list the current directory, and then use the CD command to enter a directory

Copy code

The code is as follows:

ls -l

                                                                                                         ~
drwx——   4 icafe  staff   136 Aug  9 12:34 Applications
drwx——+ 40 icafe  staff  1360 Oct 31 11:15 Desktop
drwx——+ 13 icafe  staff   442 Oct 30 19:49 Documents
drwx——+ 46 icafe  staff  1564 Oct 31 08:15
drwx——@ 57 icafe  staff  1938 Oct 27 05:45 Library
cd Library/
Bash on MAC has also made some optimizations. We can input a part of the prefix of the directory and press the tab key to complete it automatically to help us match the directory name at the beginning of the prefix

Copy code

The code is as follows:

cd Li

Press tab:

Copy code

The code is as follows:

cd Library/

The directory name will be supplemented according to the prefix matching function. However, there are still some inconveniences. For example, the automatic completion function matches the case exactly. If we input CD lib and then press tab, we can’t match the library directory, because their case doesn’t match.

Oh my Zsh provides a better solution. We enter CD Lib in the command line of oh my Zsh, and then press the tab key

Copy code

The code is as follows:

cd Library/

Successfully matched to the library directory. If we add a space after the CD command, and then press the tab key:

Copy code

The code is as follows:

cd <Tab>

Applications/  System/        bin/           dev/           net/           sbin/          [email protected]
Library / users / cores / etc @ opt / tmp @ user [email protected]
Network/       Volumes/       data/          home/          private/       usr/
It directly lists all subdirectories and files in the current directory. In this state, if we continue to press a tab key.

You will find that in this directory and file list, we can move the cursor and select:
2015118112251601.png (610×85)

This feature of oh my Zsh is very convenient.

epilogue
The best part of oh my Zsh is its community driving force. The various topics and convenient directory operation that we described above are only a small part of it. In addition, its plug-in mechanism is also very powerful, which can evolve the command line into various forms to meet our needs.