安装

zsh 安装

现在好多 linux 发行版好像都自带 zsh 的,比如说 centos。

[root@master ~]# chsh -l
/bin/sh
/bin/bash
/usr/bin/sh
/usr/bin/bash
/usr/bin/tmux
/bin/zsh
/usr/bin/fish

如果实在没有的话,就用 yum 安装一个。

yum install zsh

如果直接切换到 zsh 的话,看起来和默认 bash 好像没太大区别。

[root@master ~]# chsh
Changing shell for root.
New shell [/bin/bash]: /bin/zsh
Shell changed.

一般来说,是要配合现在很流行的 oh my zsh 来使用的。

oh my zsh 安装

[root@master]~# git clone https://github.com/ohmyzsh/ohmyzsh.git ~/.oh-my-zsh
Cloning into '/root/.oh-my-zsh'...
remote: Enumerating objects: 26567, done.
remote: Counting objects: 100% (188/188), done.
remote: Compressing objects: 100% (99/99), done.
remote: Total 26567 (delta 97), reused 166 (delta 88), pack-reused 26379
Receiving objects: 100% (26567/26567), 7.76 MiB | 61.00 KiB/s, done.
Resolving deltas: 100% (13325/13325), done.[root@master]~# cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc

使用

再次连接的话,就是下面这种的了。

Connecting to 192.168.128.139:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.WARNING! The remote SSH server rejected X11 forwarding request.
Last login: Tue Aug 24 11:14:39 2021 from 192.168.128.1➜  ~
➜  ~ cd insight-tool
➜  insight-tool git:(master) ✗ 

如果你想下次连接的时候使用默认的 bash 的话,就用 chsh 切换回去就好了。

➜  insight-tool git:(master) ✗ chsh -s /bin/bash
Changing shell for root.
Shell changed.

如果你想立即马上切换回 bash 的话,直接输入 bash 就好了。

➜  ~ bash
[root@master ~]#

如果还有安装其他的 shell, 任意切换也没有任何问题。

[root@master ~]# fish
Welcome to fish, the friendly interactive shell
Type help for instructions on how to use fish
root@master ~# zsh
➜  ~ bash
[root@master ~]#

配置

➜  ~ vim .zshrc

家目录下的这个 .zshrc 就是 zsh 的配置文件了,像主题,插件之类的就需要在里边进行配置。

其实还有个 .zsh_history ,记录了你在 zsh 下各种操作的历史记录,类似于下面这种的。前面那个大数字大家肯定很容易猜到是啥。

➜  ~ vim .zsh_history...
: 1629789654:0;vim .zshrc
: 1629789748:0;vim .zsh_history
>>> 1629789748 / 365 / 24 / 60 / 60
51.680293886352096

对,没错,稍微转换一下就容易发现:就是当前的时刻到 1970 年经历过的秒数。

主题

默认的主题时 robbyrussell,通过注释也可以看出,如果你设置主题为 ”random" 的话,每次进入 zsh 的时候它就会随机帮你选一个主题。

➜  ~ vim .zshrc# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH# Path to your oh-my-zsh installation.
export ZSH=$HOME/.oh-my-zsh# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
ZSH_THEME="robbyrussell"# Set list of themes to pick from when loading at random
# Setting this variable when ZSH_THEME=random will cause zsh to load
# a theme from this variable instead of looking in $ZSH/themes/
# If set to an empty array, this variable will have no effect.
# ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" )

为了体验一下,完全可以尝试一下。

ZSH_THEME="random"
[root@master ~]# zsh
[oh-my-zsh] Random theme 'kphoen' loaded
[root@master:~]
# bash
[root@master ~]# zsh
~ ➤  Random theme 'arrow' loaded
~ ➤  bash
[root@master ~]# zsh
/root/.oh-my-zsh/themes/emotty.zsh-theme:49: command not found: emotty
[oh-my-zsh] Random theme 'emotty' loaded
root@master  bash                                                                                                 ~
[root@master ~]# zsh
[oh-my-zsh] Random theme 'wuffers' loaded
{} ~

它所有的主题都存放在 oh-my-zsh 项目 themes 目录下的:

➜  themes git:(master) ls | head -n 10
3den.zsh-theme
adben.zsh-theme
af-magic.zsh-theme
afowler.zsh-theme
agnoster.zsh-theme
alanpeabody.zsh-theme
amuse.zsh-theme
apple.zsh-theme
arrow.zsh-theme
aussiegeek.zsh-theme

如果你想查看所有主题的效果,请转到这个链接:https://github.com/ohmyzsh/ohmyzsh/wiki/Themes

插件

插件也是在 .zshrc 这个文件里设置的,默认只配置了 git,可以自行添加。

➜  ~ vim .zshrc# ZSH_CUSTOM=/path/to/new-custom-folder# Which plugins would you like to load?
# Standard plugins can be found in $ZSH/plugins/
# Custom plugins may be added to $ZSH_CUSTOM/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(git osx autojump)source $ZSH/oh-my-zsh.sh

比如说添加 git 插件后,当你处于一个 git 受控的目录下时,Shell 会明确显示 「git」和 branch,如上图所示,另外对 git 很多命令进行了简化,例如 gco=’git checkout’、gd=’git diff’、gst=’git status’、g=’git’等等,熟练使用可以大大减少 git 的命令长度。

相关的插件文件在 ~/.oh-my-zsh/plugins 目录下,默认提供了几百种。

➜  plugins git:(master) pwd
/root/.oh-my-zsh/plugins
➜  plugins git:(master) ls | wc301     301    2379

每个插件都有相应的 README.md 说明文档,可以自行了解插件的功能和用法。

➜  plugins git:(master) cd git
➜  git git:(master) ll
total 44K
-rw-r--r--. 1 root root 9.4K Aug 24 11:13 git.plugin.zsh
-rw-r--r--. 1 root root  31K Aug 24 11:13 README.md

我大概看了几个,大部分主要时设置常用命令的别名,用户就可以不用输入全称了,比如 yum 的这个插件。

➜  yum git:(master) pwd
/root/.oh-my-zsh/plugins/yum
➜  yum git:(master) ll
total 8.0K
-rw-r--r--. 1 root root 1.4K Aug 24 11:13 README.md
-rw-r--r--. 1 root root  864 Aug 24 11:13 yum.plugin.zsh
➜  yum git:(master) vim README.md
# Yum pluginThis plugin adds useful aliases for common [Yum](http://yum.baseurl.org/) commands.To use it, add `yum` to the plugins array in your zshrc file:```zsh
plugins=(... yum)
```## Aliases| Alias | Command                           | Description                  |
|-------|-----------------------------------|------------------------------|
| ys    | `yum search`                      | Search package               |
| yp    | `yum info`                        | Show package info            |
| yl    | `yum list`                        | List packages                |
| ygl   | `yum grouplist`                   | List package groups          |
| yli   | `yum list installed`              | Print all installed packages |
| ymc   | `yum makecache`                   | Rebuild the yum package list |
| yu    | `sudo yum update`                 | Upgrade packages             |
| yi    | `sudo yum install`                | Install package              |
| ygi   | `sudo yum groupinstall`           | Install package group        |
| yr    | `sudo yum remove`                 | Remove package               |
| ygr   | `sudo yum groupremove`            | Remove pagage group          |
| yrl   | `sudo yum remove --remove-leaves` | Remove package and leaves    |
| yc    | `sudo yum clean all`              | Clean yum cache              |

Linux 之 zsh相关推荐

  1. linux安装zsh终端

    linux安装zsh终端 ZSH 已经被收录到了 Ubuntu 18.04 LTS 的官方软件包存储库中了 sudo apt install zsh ZSH Shell 安装好之后,可以使用如下命令查 ...

  2. linux zsh 终端,linux安装zsh终端

    linux安装zsh终端 ZSH 已经被收录到了 Ubuntu 18.04 LTS 的官方软件包存储库中了 sudo apt install zsh ZSH Shell 安装好之后,可以使用如下命令查 ...

  3. linux zsh ping命令,扣丁学堂Linux培训简述Linux使用zsh提高效率的5条建议

    本篇文章扣丁学堂Linux培训小编给大家分享一下Linux使用zsh提高效率的5条建议,对Linux开发技术感兴趣或者还是想要加入到Linux开发领域的小伙伴可以随小编一起来了解一下哦. Linux培 ...

  4. linux zsh命令行vim命令补齐,Linux使用zsh提高效率的5条建议

    平时比较喜欢命令行,不喜欢从图形化界面一个个的点过去:感觉还是命令搜索,查找方便些,快速些.但是,Bash本身提供的功能又不够方便,自己也懒得折腾.幸得github上有前辈大神们开源的 zsh工具集, ...

  5. linux fedora35 zsh oh-my-zsh 的配置与使用

    gitee下载地址: https://gitee.com/mirrors/oh-my-zsh?_from=gitee_search 众所周知,大部分的Linux发行版的默认命令解释器是Bash.但除此 ...

  6. linux shell zsh,Linux终极shell Z Shell 用强大的zsh oh-my-zsh把Bash换掉

    Bash确实是不错的Shell,但仍有用不少不尽人意的地方,如自动补全的功能不够强大,定位较长路径不够方便,命令历史管理不够完善等.javascript 介绍使用zsh,功能十分强大-推荐给你们!ja ...

  7. Linux中zsh插件,ubuntu / zsh shell / oh-my-zsh / 常用插件

    记录一下 zsh 的下载与配置,省得每次重装系统都要上网到处查. 安装 zsh shell sudo apt install zsh 切换 shell chsh -s /bin/zsh 安装 oh-m ...

  8. Linux中zsh插件,Zsh 常用插件

    zsh有了各种插件后才真是如虎添翼,各种命令高亮,自动补全,命令参数辅助等. zsh插件安装方法 各种插件的安装方法各异,有的直接将插件文件夹拷贝到~/.oh-my-zsh/custom/plugin ...

  9. Linux 安装zsh和zsh的配置

    1.在安装之前,需要了解一些自己的shell是什么. 命令:echo $SHELL 这里是bash shell环境. 2.安装zsh 输入命令:sudo pacman -S zsh         直 ...

最新文章

  1. 关于TypeError: ‘numpy.ndarray‘ object is not callable报错
  2. 基于图机器学习的微生物网络关系预测算法研究
  3. 使用Ptrace跟踪进程收到的异常信号(信号SIGTRAP是通过traceme后wait得到的)
  4. vscode编辑器自动格式化
  5. 我都惊了这么多年pytorch还可以这么用
  6. BZOJ 2049: [Sdoi2008]Cave 洞穴勘测
  7. Ubuntu SSH root user cannot login
  8. [HNOI2017]单旋
  9. php传递字符串给python,用PHP和Python生成短链接服务的字符串ID
  10. 我国共招过多少博士?多少硕士?数据来了!
  11. 【转】 NSArray copy 问题
  12. SpringCloud与zuul
  13. 做YH更新,引发众多思考.
  14. 什么是Thymeleaf?
  15. C10K 和 C1000K 回顾
  16. VS2010提示asp.net v4.0 尚未在web服务器上注册
  17. Clustering - Choosing the number of clusters
  18. 让你在macOS上快速查看txt文本文件
  19. 60mph和kmh换算_mph和kmh换算(mph换算器)
  20. SAP请求释放怎么撤回

热门文章

  1. 安装多版本Chrome
  2. Android 音视频深入 十 FFmpeg给视频加特效(附源码下载)
  3. C/C++抽红包系统
  4. 企业微信公众号内容写什么好?微信公众号如何选题?
  5. imprecise external abort
  6. [ Azure - IAM ] Azure 中的基于角色的访问控制 (RBAC) 与基于属性的访问控制 (ABAC)
  7. 源码编译安装git过程记录
  8. Mac VMware Fusion提示物理内存不足
  9. 计算机如何通过手机连接网络打印机,无需计算机即可将手机直接连接到打印机的步骤...
  10. 记一个chrome自带input:-internal-autofill-selected背景色样式问题