zsh(Z-shell)终极shell

0x00 安装zsh当然是为了让我们输命令的时候更流畅啦~

0x01 Zsh安装:


ubuntu: apt-get install zsh

centos : yum install zsh



检查系统的shell安装: cat /etc/shells,有了/bin/zsh则安装成功


0x02 使用zsh扩展集合: oh-my-zsh

  • oh-my-zsh 帮我们整理了一些常用的扩展功能和主题

  • 先安装 git :sudo apt-get install git curl wget

  • 安装oh-my-zsh


sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"



wget https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O - | sh
  • 在以root用户运行,安装目录为:/root/.oh-my-zsh Zsh的配置文件位置:/root/.zshrc

  • 为root用户设置zsh为系统默认shell:


chsh -s /bin/zsh root

或者

vim /etc/passwd 

root: *****:/bin/bash -> /bin/zsh
  • 重新连接shell,shell则变为zsh

0x03 修改oh-my-zsh主题为bira


cd

vim .zshrc



:11

"bira"

0x04:Zsh配置

  • zsh-autosuggestion

自动补全插件


git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions



vim ~/.zshrc

-> plugins=(zsh-autosuggestion)

source

命令语法高亮插件


将插件下载到oh my zsh的插件目录下的该新建插件同名文件夹中

git clone https://github.com/zsh-users/zsh-syntax-highlighting.git $ZSH_CUSTOM/plugins/zsh-syntax-highlighting



编辑~/.zshrc文件将然后将插件引用命令写入该文件最后一行(必须)

# Note the source command must be at the end of .zshrc

source "$ZSH_CUSTOM/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh"


:73


plugins=(

        git

        zsh-autosuggestions

        zsh-syntax-highlighting

        )

0x05:自定义Zsh配置prompt

以bira主题为例

~/.oh-my-zsh/themes/bira.zsh-theme


%n	用户名

%m	主机名

%#	%


0xff:自编辑脚本一键安装并修改


#!/bin/bash

sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" &&



git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions



git clone https://github.com/zsh-users/zsh-syntax-highlighting.git $ZSH_CUSTOM/plugins/zsh-syntax-highlighting



sed -i 's/robbyrussell/bira/g' .zshrc;

sed -i 's/=(git/=(\n\tgit\n\tzsh-autosuggestions\n\tzsh-syntax-highlighting\n\t/g' .zshrc;

sed 's/)%n@%m/)YourWantSymbol@%m/g' .oh-my-zsh/themes/bira.zsh-theme;