A Beautiful Shell for Linux

From: Beginner's Station

Let’s start with a beautiful image

A Beautiful Shell for Linux

1. Introduction to zsh

1.1 Linux Shell

Linux/Unix provides many types of shells; why so many shells?

Are they for cooking? Let me ask you, why do you have so many similar clothes? Different colors and textures. Writing programs is much more complex than buying clothes, and programmers often have to simplify complex tasks and complicate simple ones. A skilled programmer who is dissatisfied with a shell will rewrite it, gradually forming some standards. The commonly used shells include sh, bash, csh, etc. To find out how many shells your system has, you can use the following command:

cat /etc/shells

The output is as follows:

A Beautiful Shell for Linux

1.2 Introduction to zsh

Zsh is a powerful shell for Linux. Although most Linux distributions install and use the <span>bash shell</span>, this does not diminish the enthusiasm of geeks for zsh. Almost every Linux distribution includes zsh, which can usually be installed using package managers like apt-get, urpmi, or yum.

Zsh has the following main features:

  • Out-of-the-box, programmable command-line completion helps users input various parameters and options.

  • Shares command history across all shells started by the user.

  • Through extended file globbing, it can expand filenames like the find command without using external commands.

  • Improved variable and array handling.

  • Allows editing of multi-line commands in the buffer.

  • Multiple compatibility modes, such as masquerading as the Bourne shell when running /bin/sh.

  • Customizable prompt presentation; including displaying information on the right side of the screen and automatically hiding when typing long commands.

  • Loadable modules provide various additional support: complete TCP and Unix domain socket control, FTP client, and extended mathematical functions.

  • Fully customizable.

1.3 Ultimate Configuration of zsh and oh-my-zsh

I chose to use zsh after seeing this article: The Ultimate Shell – Zsh, attracted by its auto-completion and completion features. Official website: www.zsh.org

I chose oh-my-zsh, which is an extension of zsh’s functionality, providing convenient plugin management, theme customization, and beautiful auto-completion effects.

I discovered it while looking for zsh projects on GitHub, and found it very convenient; it doesn’t require the complex configuration mentioned in the article above, just configure the names of the plugins to use the corresponding features.

Official website: https://github.com/robbyrussell/oh-my-zsh

2. Installing zsh

2.1 Installing zsh

For a typical Ubuntu system, after configuring the correct sources, you can directly enter the following command to install:

sudo apt-get install zsh

2.2 Configuring zsh

Configuring zsh is a complex topic; here I will provide a configuration file that you can download and place in the zsh configuration directory for direct use. (A French friend of mine prepared it, and it’s quite handy.)

Copy .zshrc to the corresponding user’s home directory (you can also copy your bash configuration file (~/.bash_profile or ~/.profile, etc.) to zsh’s configuration file ~/.zshrc, as zsh is compatible with bash).

2.3 Replacing bash and setting as default shell

sudo usermod -s /bin/zsh username

Or

chsh -s /bin/zsh

chsh -s `which zsh`

If you want to switch back to bash:

chsh -s /bin/bash

If you really don’t want to make zsh your default shell but still want to use it, you can enter it every time by typing<span>zsh</span> and exit by typing<span>exit</span>.

A Beautiful Shell for Linux

2.4 Installing oh-my-zsh

Using zsh directly can be quite cumbersome because zsh is powerful but too complex, so oh-my-zsh is needed to simplify it.

Directly download the package from GitHub using git

git clone git://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh

Backup the existing zshrc and replace zshrc

cp ~/.zshrc ~/.zshrc.orig
cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc

Directly use the script to install

cd oh-my-zsh/tools
./install.sh

You can directly use the following command to install

curl

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

wget

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

The essence is to download and execute the install.sh script from GitHub, which is located at<span>oh-my-zsh/tools/install.sh</span>

Configuring Themes

oh-my-zsh integrates a large number of themes, located in <span>oh-my-zsh/theme</span>

To configure a theme, you can modify the environment variable<span>ZSH_THEME</span> in<span>~/.zshrc</span> as follows:

ZSH_THEME="agnoster" # (this is one of the fancy ones)

If you think there are too many themes, you can choose to use random mode, allowing the system to randomly select:

ZSH_THEME="random" # (...please let it be pie... please be some pie..)

A Beautiful Shell for Linux

For detailed theme information, please refer to the zsh theme introduction.

Configuring Plugins

Modify<span>~/.zshrc</span> in the<span>plugins</span>

plugins=(git bundler osx rake ruby)

For detailed plugin information, please refer to the zsh plugin introduction.

Updating oh-my-zsh

By default, you will be prompted to check for updates every few weeks. If you want oh-my-zsh to automatically update itself without prompting you, modify <span>~/.zshrc</span>

disable_update_prompt = true

To disable automatic updates, modify <span>~/.zshrc</span>

disable_auto_update = true

Of course, you can also choose to update manually.

If you want to upgrade at any time (maybe someone just released a new plugin, and you don’t want to wait a week?), you just need to run:

upgrade_oh_my_zsh

Uninstalling oh-my-zsh

If you want to uninstall<span>oh-my-zsh</span>, just execute<span>uninstall_oh_my_zsh zsh</span> from the command line. This will remove it and restore your previous bash or zsh configuration.

uninstall_oh_my_zsh zsh
— EOF —

Recommended↓↓↓

Leave a Comment