Super beautiful shell for Linux

Linux中文社区
Linux中文社区forward
2023-08-02 15:38:121425browse

First a beautiful picture

Super beautiful shell for Linux


##1 zsh introduction

1.1 Linux shell

Linux/Unix provides many kinds of Shells, why do you need so many Shells?

Is it used for frying? Then let me ask you, why do you have so many pieces of the same type of clothes? The color and texture are different. Writing a program is much more complicated than buying clothes, and programmers are often responsible for making complex things simple and simple things complicated. When great programmers see a shell they are unhappy with, they will rewrite it themselves and gradually form some standards. There are several commonly used shells, such as sh, bash, csh, etc. If you want to know how many shells your system has, you can View through the following command:

cat /etc/shells

The display is as follows:

Super beautiful shell for Linux

1.2 Introduction to zsh

Zsh is a powerful shell under Linux. Since most Linux products are installed and use bash by default shell, but this does not affect geeks' enthusiasm for zsh at all. Almost every Linux product contains zsh, which can usually be installed using package managers such as apt-get, urpmi or yum

Zsh has the following main functions

  • Out-of-the-box, programmable command line completion function can help users enter various parameters and options

  • Sharing command history among all shells started by the user

  • With extended file wildcards, this can be achieved without using external commands The find command generally expands file names

  • Improved variable and array handling

  • In the buffer Edit multi-line commands in the zone

  • ##Multiple compatibility modes, for example, you can disguise yourself as Bourne shell when running with /bin/sh

  • 可以定制呈现形式的提示符;包括在屏幕右端显示信息,并在键入长命令时自动隐藏

  • 可加载的模块,提供其他各种支持:完整的 TCP 与 Unix 域套接字控制,FTP 客户端与扩充过的数学函数

  • 完全可定制化

1.3 zsh 与 oh-my-zsh 终极配置

之前是因为看到这篇文章:终极 Shell——Zsh 才选择使用 zsh,被它的自动完成、补全功能吸引了。官网:www.zsh.org

选择 oh-my-zsh, oh-my-zsh 是基于 zsh 的功能做了一个扩展,方便的插件管理、主题自定义,以及漂亮的自动完成效果。

在 Github 上找关于 zsh 的项目时发现的,试用了一下觉得很方便,不用像上面文章里面提到的那么复杂,配置一些插件的名称即可使用相应的功能。

牛逼啊!接私活必备的 N 个开源项目!赶快收藏

官网:https://github.com/robbyrussell/oh-my-zsh

2 安装 zsh

2.1 安装 zsh

对于一般的 Ubuntu 系统,配置好正确的源之后,就能直接键入以下命令安装:

sudo apt-get install zsh

2.2 配置 zsh

zsh 的配置是一门大学问,这里不赘述,直接给出一个配置文件,大家可以下载后放入 zsh 配置文档直接使用。(我的一个法国朋友手配的,相当顺手)

把. zshrc 拷贝到相应用户的 home 目录即可(也可以把你的 bash 的配置文件 (~/.bash_prorile 或者~/.profile 等) 给拷贝到 zsh 的配置文件~/.zshrc 里,因为 zsh 兼容 bash)

2.3 取代 bash,设为默认 shell

sudo usermod -s /bin/zsh username

或者

chsh -s /bin/zsh
chsh -s `which zsh`

如果要切换回去 bash:

chsh -s /bin/bash

当然你实在不愿意把 zsh 当成默认的 shell, 而又想使用它, 那么你可以每次进入是都使用zsh进入, 而输入exit退出

Super beautiful shell for Linux

2.4 安装 oh-my-zsh

直接用 zsh 会很蛋疼,因为 zsh 功能很强大但是太复杂,所以需要 oh-my-zsh 来将它简单化。另外,搜索公众号Linux就该这样学后台回复“Linux”,获取一份惊喜礼包。

直接用 git 从 github 上面下载包

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

备份已有的 zshrc, 替换 zshrc

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

直接使用脚本安装

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

你可以直接直接使用如下命令安装

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 -)"

其本质就是下载并执行了 github 上的 install.sh 脚本, 该脚本位于oh-my-zsh/tools/install.sh

配置主题

oh-my-zsh 集成了大量的主题, 位于 oh-my-zsh/theme

配置主题, 可以通过修改~/.zshrc中的环境变量ZSH_THEME来完成

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

如果你觉得主题太多你可以选择使用随机模式, 来由系统随机选择

ZSH_THEME="random" # (...please let it be pie... please be some pie..)
Super beautiful shell for Linux

详细的主题信息, 可以参见 zsh 主题介绍

配置插件

修改~/.zshrcplugins

plugins=(git bundler osx rake ruby)

详细的插件信息, 可以参见 zsh 插件 Plugins 介绍

更新 oh-my-zsh

默认情况下, 您将被提示检查每几周的升级. 如果你想我 ZSH 自动升级本身没有提示你, 修改 `~/.zshrc。另外,搜索公众号顶级算法后台回复“算法”,获取一份惊喜礼包。

disable_update_prompt = true

禁用自动升级, 修改~/.zshrc

disable_auto_update = true

当然你也可以选择手动更新

如果你想在任何时间点升级(也许有人刚刚发布了一个新的插件,你不想等待一个星期?) 你只需要运行:

upgrade_oh_my_zsh

卸载 oh-my-zsh

If you want to uninstall oh-my-zsh, just execute uninstall_oh_my_zsh zsh, run from the command line. This will delete itself and restore your previous bash or zsh configuration.

The above is the detailed content of Super beautiful shell for Linux. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:Linux中文社区. If there is any infringement, please contact admin@php.cn delete