Configure zsh in Ubuntu

Source: Internet
Author: User
Tags git commands

Configure zsh in Ubuntu

 

 

Before starting MacTalk today, let's ask two questions:

1. What are the main advantages of Mac over other systems?
2. What Shell do you usually use?
......

The first child boots can sit down. The biggest advantage of Mac is the perfect combination of GUI and command line. Don't put all your attention on Mac's sexy waist and bright display. Okay, it's not my sister paper! You can go out to the wall with the second child boots. After talking about MacTalk for so many times, you tell me that Windows cmd is still in use. How can you make Mac feel? Even if you say you are using Linux Bash, I will forgive you and kill!

The last time I mentioned Shell in "How to Learn a programming language", some readers asked questions about Shell, so this time I will tell you about Shell.

I introduced a little Shell in "fun talk about personal website building". I borrowed some of my things and kept them as follows:

Shell is a Shell of Linux/Unix. You can understand it as a dress. It is responsible for external interaction with the Linux kernel, receiving commands from users or other applications, and then converting these commands into languages that the kernel can understand and passing them to the kernel, then, return the result to the user or application.

Linux/Unix provides many types of Shell. Is it necessary for so many Shell? Is it used for fried food? Then I ask you, how are there so many clothes of the same type? Different colors and textures. Writing a program is much more complicated than buying clothes, and programmers are often responsible for making complicated things simple and simple. When a programmer sees an uncomfortable Shell, he will write a new set by himself and gradually form some standards. There are several common Shell types, such as sh, bash, and csh, you can run the following command to check whether your system has several shells:

cat /etc/shells

Shown as follows:

/bin/bash/bin/csh/bin/ksh/bin/sh/bin/tcsh/bin/zsh

Running this command in Linux is slightly different from Mac. You will find that there is a zsh in Mac, that is, the OS X system has a zsh preinstalled. What about this Shell?

Currently, the common Linux System and the default Shell of OS X are bash, but the real powerful Shell is the hidden zsh, which is definitely a sports car in a carriage, a flying car in a sports car, the "ultimate Shell" is called in history. However, the configuration is too complicated, so no one cares about it in the early stage. Many people come to see the zsh Configuration Guide and leave without saying anything. One day, a very boring programmer from abroad developed a zsh project called "oh my zsh 」, this is like the series "X days tell you to learn C ++", which can make your work more efficient and true.

Now let's take a look at how to install, configure, and use zsh.

Install zsh

If you use Mac, you can view the next section.
If you use Redhat Linux, run: sudo yum install zsh
If you use Ubuntu Linux, run: sudo apt-get install zsh.
If you use Windows ...... Go to wash and sleep.

After the installation is complete, set the current user to use zsh: chsh-s/bin/zsh, and enter the current user's password as prompted.

Install oh my zsh

Install git first. The installation method is the same as above. Replace zsh with git.

Install "oh my zsh" automatically or manually.

Automatic installation:

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

Manual installation:

git clone git://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zshcp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc

It is not complex. After the installation is complete, exit the current session and open a terminal window again. Then you can see the color prompt:

Configuration

Zsh configurations are mainly concentrated in the. zshrc file in the current directory of the user. Open. zshrc in vim or other editors you like, and you will find such a line at the bottom:

# Customize to your needs...

You can define your own environment variables and aliases here. Of course, oh my zsh has automatically read and set the current environment variables during installation. You can continue to append other environment variables.

Next, set the alias. My own configuration is as follows:

Alias cls = 'clear' alias ll = 'LS-l' alias la = 'LS-a' alias vi = 'vim 'alias javac = "javac-J-Dfile.encoding = utf8" alias grep = "grep -- color = auto" alias-s html = mate # enter the file name suffixed with html in the command line, alias-s rb = mate # Open the ruby file in TextMate. alias-s py = vi # Open the python file in TextMate, it will be opened in vim, the following is similar to alias-s js = vialias-s c = vialias-s java = vialias-s txt = vialias-s gz = 'tar-xzvf 'alias-s tgz = 'tar- xzvf 'Alias-s zip = 'unzip' alias-s bz2 = 'tar-xjvf'

Zsh's cow dung is that it can not only set a general alias, but also set the corresponding open program for the file type, such:

Alias-s html = mate, which means you enter hello.html in the command line. zsh will automatically open TextMat for you and read hello.html; alias-s gz = 'tar-xzvf ', automatically decompress the zip package suffixed with gz.

In a word, you can't do it without thinking of it. Just scare yourself.

After setting environment variables and aliases, you can basically use them. If you are a theme controller, you can also play with zsh themes. Find ZSH_THEME in. zshrc to set the topic. The default topic is:

ZSH_THEME = "robbyrussell"

Oh my zsh provides dozens of themes ~ /. Under the oh-my-zsh/themes directory, you can select or edit the topic to meet your abnormal needs. I used the default topic robbyrussell, but made a small change:

PROMPT='%{$fg_bold[red]%}? %{$fg_bold[green]%}%p%{$fg[cyan]%}%d %{$fg_bold[blue]%}$(git_prompt_info)%{$fg_bold[blue]%}% %{$reset_color%}>'#PROMPT='%{$fg_bold[red]%}? %{$fg_bold[green]%}%p %{$fg[cyan]%}%c %{$fg_bold[blue]%}$(git_prompt_info)%{$fg_bold[blue]%} % %{$reset_color%}'

In contrast to the original version, I changed c to d, c to the current directory, and d to the absolute path. In addition, I added a ">" at the end. The effect after the change is as follows:

You can try to make changes.

Finally, let's talk about plug-ins.

Plug-ins

The oh my zsh project provides a complete plug-in system ~ /. By default, the oh-my-zsh/plugins directory provides more than 100 types. You can use it based on your actual learning and working environment. To learn about the functions of each plug-in, you just need to open the zsh file in the relevant directory and check it. The plug-in is also configured in. zshrc. Find the plugins keyword and you will be able to load your plug-in. By default, the system loads git. You can append the following content:

plugins=(git textmate ruby autojump osx mvn gradle)

The following is a brief introduction:

1. git: when you are in a git-controlled directory, the Shell will clearly display "git" and branch, as shown in. In addition, many git commands are simplified, for example, gco = 'git checkout', gd = 'git diff', gst = 'git status', g = 'git ', and so on. Skilled use can greatly reduce the git command length, for more information about the command content, see ~ /. Oh-my-zsh/plugins/git. plugin. zsh

2. textmate: mr can create ruby framework projects, and tm finename can use textmate to open the specified file.

3. osx: tab enhancement. quick-look filename can be used to preview files directly. man-preview grep can be used to generate a pdf version of The grep manual.

4. autojump: the combination of zsh and autojump forms the most powerful plug-in zsh. Today we will mainly talk about this product.

First install autojump. If you use Mac, use brew to install it:

brew install autojump

For Linux, download the latest version of autojump, for example:

git clone git://github.com/joelthelion/autojump.git

Decompress the package and enter the directory. Execute

./install.py

Add the following code to. zshrc:

[[ -s ~/.autojump/etc/profile.d/autojump.sh ]] && . ~/.autojump/etc/profile.d/autojump.sh

So far, the three-in-one installation, configuration, and plug-in have fully appeared in the ultimate Shell. Log out of the terminal session and log on again to start to feel the zsh training!

Use zsh

1. It is compatible with bash. It is easy to switch from a bash brother.

2. Powerful history function. Enter grep and use the up and down arrows to view all the grep commands you run.

3. Enter gtep mactalk *-R and the system will prompt zsh: correct 'gtep' to 'grep' [nyae]? It's more intimate than sister paper. They always make you guess ......

4. Various completions: path completion, command completion, command parameter completion, and plug-in content completion. To trigger completion, you only need to press the tab key one or two times. You can use ctrl + n/p/f/B to switch between top, bottom, and left. For example, if you want to kill a java Process, you only need to enter the kill java + tab key. If there is only one java Process, zsh will be automatically replaced with the pid of the process, if there are multiple options, you can select them. Ssh + space + two tab keys, zsh will list all accessed hosts and usernames for completion

5. Smart jump. After autojump is installed, zsh automatically records the directories you have accessed. You can directly perform directory jump using the j + directory name, and the directory name supports fuzzy match and Automatic completion, for example, you have accessed the hadoop-1.0.0 directory, enter j hado to jump correctly. J-stat can be used to view your historical path library.

6. directory browsing and navigation: enter d to list the directories you have accessed in this session. Enter the sequence number before the list to directly jump.

7. Enter... in the current directory... , Or directly enter the current directory name to jump, you do not even need to enter the cd command.

8. wildcard search: ls-l **/*. sh. You can recursively display the shell files in the current directory. If there are few files, you can replace find. If there are too many files, you can stop.

9. Stronger aliases: see the configuration section.

10. Plug-in support: see the plug-in section.

......

After reading this article, you will know that as soon as zsh is published, no one will compete with us! The Ultimate 2 character is not covered.

If you are a shell programmer and you are still using bash, go to the wall and confess, let alone you have subscribed to MacTalk!

Thanks to the boring programmer who developed oh my zsh, he may not reap material benefits, but his code has improved the efficiency of countless programmers and saved a lot of time, we say that programmers change the world!

MacTalk writes a lot, and friends and family do not quite understand it. It cannot make money and cannot compete for a name. How can it be used? I think it is better to learn, code, write, and do something that helps others. Although people are richer than others ......


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.