zsh & oh-my-zsh 安装配置

1 安装 zsh

1
2
3
4
5
sudo apt install zsh

# echo $SHELL # 显示当前 shell 类型
# cat /etc/shells # 显示可使用的 shell
# chsh -s /bin/zsh # 将 zsh 设为默认终端

2 安装 ohmyzsh

ref: https://ohmyz.sh/

  • 用 wget 安装。
    1
    sh -c "$(wget https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh -O -)"

有时候会出现 443 网路错误,可手动下载、安装 install.sh

1
nano zsh-install.sh

打开 https://github.com/ohmyzsh/ohmyzsh/blob/master/tools/install.sh
将安装代码全部复制进去

1
2
sudo chmod +x zsh-install.sh
./zsh-install.sh

3 安装 ohmyzsh (gitee 源)

ref: https://gitee.com/mirrors/oh-my-zsh.git

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

4 配置 ohmyzsh (gitee 源)

  • 打开配置文件

    1
    nano ~/.zshrc
  • 修改如下:

    1
    2
    3
    4
    5
    # 主题
    ZSH_THEME="ys"

    # 插件
    plugins=(git zsh-autosuggestions zsh-syntax-highlighting )
  • 也可以用命令修改:

    1
    2
    sed -i 's/^ZSH_THEME=.*/ZSH_THEME="ys"/g' .zshrc
    sed -i 's/^plugins=.*/plugins=(git zsh-autosuggestions zsh-syntax-highlighting)/g' .zshrc
  • 下载插件

    1
    2
    3
    git clone https://gitee.com/mirrors/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

    git clone https://gitee.com/mirrors/zsh-syntax-highlighting ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

    ref: https://github.com/zsh-users/zsh-autosuggestions

ref: https://github.com/zsh-users/zsh-syntax-highlighting

  • 加载配置文件, 使生效
    1
    source ~/.zshrc

===

1
2
3
4
5
6
7
8
9
10
11
12
sudo apt install zsh -y
sudo apt install git -y

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

sed -i 's/^ZSH_THEME=.*/ZSH_THEME="ys"/g' .zshrc
sed -i 's/^plugins=.*/plugins=(git zsh-autosuggestions zsh-syntax-highlighting)/g' .zshrc

git clone https://gitee.com/mirrors/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
git clone https://gitee.com/mirrors/zsh-syntax-highlighting ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

source ~/.zshrc