oh-my-zsh安装

介绍

https://github.com/ohmyzsh/ohmyzsh

安装步骤

  1. zsh 安装
  2. oh-my-zsh 安装、高亮&自动补全插件安装
  3. autojump 插件安装

安装脚本

MacOS:
mac 自带 zsh

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:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

# 不安装autojump
sed -i "" "s/plugins=(git)/plugins=(git zsh-autosuggestions zsh-syntax-highlighting)/g" ~/.zshrc
source ~/.zshrc

# 安装autojump
brew install autojump

sed -i "" "s/plugins=(git)/plugins=(git zsh-autosuggestions zsh-syntax-highlighting autojump)/g" ~/.zshrc
source ~/.zshrc

Ubuntu:

sudo apt update -y
sudo apt install zsh -y
sudo apt install git -y

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:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

# 不安装autojump
sed -i "s/plugins=(git)/plugins=(git zsh-autosuggestions zsh-syntax-highlighting)/g" ~/.zshrc
source ~/.zshrc

# 安装autojump
sudo apt install autojump -y

sed -i "s/plugins=(git)/plugins=(git zsh-autosuggestions zsh-syntax-highlighting autojump)/g" ~/.zshrc
source ~/.zshrc

CentOS:

sudo yum update -y
sudo yum install zsh -y
sudo yum install git -y

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:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

# 不安装autojump
sed -i "s/plugins=(git)/plugins=(git zsh-autosuggestions zsh-syntax-highlighting)/g" ~/.zshrc
source ~/.zshrc

# 安装autojump
sudo yum install -y autojump-zsh

sed -i "s/plugins=(git)/plugins=(git zsh-autosuggestions zsh-syntax-highlighting autojump)/g" ~/.zshrc
source ~/.zshrc

访问 raw.githubusercontent.com 404 时

手动安装

git clone https://github.com/ohmyzsh/ohmyzsh.git ~/.oh-my-zsh
# 如果已存在~/.zshrc文件需要额外执行下面这句
# cp ~/.zshrc ~/.zshrc.orig
cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc
chsh -s $(which zsh)

其他配置

# 如果没有切换shell成功
chsh -s $(which zsh)
# 常显主机名hostname
echo "PROMPT=%m\ \$PROMPT" >> ~/.zshrc
# 常显用户名username和主机名hostname
echo "PROMPT=\$USER@%m\ \$PROMPT" >> ~/.zshrc
# 生效
source ~/.zshrc