一、安装oh-my-zsh

  • 此版本已经自带了 zsh

    1
    2
    3
    4
    cat /etc/shells
    # /bin/zsh
    # 如果没有,执行指令安装
    apt install zsh
  • 将zsh设置为默认终端,退出shell,重开终端,如果设置不生效,重启系统即可。

    1
    2
    3
    echo $SHELL	# 查看当前终端,默认是bash
    chsh -s /bin/zsh # 设置默认终端为zsh
    chsh -s /bin/bash # 切换回bash终端
  • 安装zsh完成后,进入官网:https://ohmyz.sh/#install,使用命令进行安装 oh-my-zsh

    1
    2
    3
    4
    5
    # curl 方式
    $ sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

    # 或 wget 方式
    $ sh -c "$(wget https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh -O -)"
  • 注意:由于“不知名原因”,可能出现无法下载情况,如:installer: Failed to connect to github: Connection refused,此处可从github上寻找解决方法。

    1
    2
    3
    4
    5
    6
    7
    8
    cp /etc/hosts /etc/hosts.bak # 备份
    echo "140.82.113.3 github.com">>/etc/hosts
    echo "185.199.110.133 raw.githubusercontent.com">>/etc/hosts

    # 安装
    git clone git://github.com/ohmyzsh/ohmyzsh.git ~/.oh-my-zsh
    cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc
    source ~/.zshrc
  • 退出shell,重开终端,如果设置不生效,重启系统即可。

二、安装自动补全插件和高亮插件

  • 参考链接: https://www.jianshu.com/p/9c8c4886281f.

  • 自动补全插件下载

    1
    2
    cd $ZSH/custom/plugins
    git clone https://github.com/zsh-users/zsh-autosuggestions.git
  • 高亮插件下载

    1
    2
    cd $ZSH/custom/plugins
    git clone https://github.com/zsh-users/zsh-syntax-highlighting.git
  • 修改 ~/.zshrc

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    vim ~/.zshrc

    # 修改 plugins=(git)
    plugins=(git zsh-autosuggestions zsh-syntax-highlighting)

    # 添加
    source $ZSH/custom/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh
    source $ZSH/custom/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
    # 使配置生效,执行
    source ~/.zshrc
  • 退出shell,重开终端,如果设置不生效,重启系统即可。