跳轉到內容

oh-my-zsh 安裝 & 配置

sh
brew install zsh zsh-completions
# 把zsh設為默認shell,如果shell列表中沒有zsh或者你沒有使用chsh權限的時候,不起作用
echo $SHELL
sudo chsh -s $(which zsh)
# 或
chsh -s /bin/zsh
sh
sudo apt install zsh
chsh -s /bin/zsh

安裝git

TIP

如有請忽略此步

sh
brew install git
sh
sudo apt install git

oh-my-zsh 安裝 & 配置

安裝

sh
brew install zsh
sh
sh -c "$(wget -O- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
sh
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
sh
sh -c "$(fetch -o - https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

配置主題

sh
vim ~/.zshrc

# 找到 ZSH_THEME
ZSH_THEME="awesomepanda"

# ZSH_THEME="樣式名稱"

隨機主題

sh
ZSH_THEME="random"

oh-my-zsh 插件推薦

autojump

sh
# 安裝步驟
brew install autojump

vim ~/.zshrc
# 在文件裡找到plugins,添加
plugins=(autojump)

# 在文件末尾添加
[[ -s $(brew --prefix)/etc/profile.d/autojump.sh ]] && . $(brew --prefix)/etc/profile.d/autojump.sh
source $ZSH/oh-my-zsh.sh

# 最後
source ~/.zshrc
sh
# 安裝步驟
cd ~/.oh-my-zsh/custom/plugins/
git clone https://github.com/wting/autojump.git

vim ~/.zshrc
# 在文件裡找到plugins,添加
plugins=(autojump)

# 最後
source ~/.zshrc

zsh-autosuggestion

sh
# 安裝步驟
brew install zsh-autosuggestion

vim ~/.zshrc
# 在文件裡找到plugins,添加
plugins=(
  autojump
  zsh-autosuggestions
)

# 最後
source ~/.zshrc
sh
# 安裝步驟
cd ~/.oh-my-zsh/custom/plugins/
git clone https://github.com/zsh-users/zsh-autosuggestions.git

vim ~/.zshrc
# 在文件裡找到plugins,添加
plugins=(
  autojump
  zsh-autosuggestions
)

# 最後
source ~/.zshrc

zsh-syntax-highlighting

sh
# 安裝步驟
brew install zsh-syntax-highlighting

vim ~/.zshrc
# 在文件裡找到plugins,添加
plugins=(
  autojump
  zsh-autosuggestions
  zsh-syntax-highlighting
)

# 最後
source ~/.zshrc
sh
# 安裝步驟
cd ~/.oh-my-zsh/custom/plugins/
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git

vim ~/.zshrc
# 在文件裡找到plugins,添加
plugins=(
  autojump
  zsh-autosuggestions
  zsh-syntax-highlighting
)

# 最後
source ~/.zshrc

zsh-completions

sh
# 安裝步驟
brew install zsh-completions

vim ~/.zshrc
# 在文件裡找到plugins,添加
plugins=(
  autojump
  zsh-autosuggestions
  zsh-syntax-highlighting
  zsh-completions
)

# 添加如下配置
FPATH=$(brew --prefix)/share/zsh-completions:$FPATH

# 使配置生效
source ~/.zshrc

# 刪除~/.zcompdump文件
rm -f ~/.zcompdump

# 重新生成~/.zcompdump文件
compinit
sh
# 安裝步驟
cd ~/.oh-my-zsh/custom/plugins/
git clone https://github.com/zsh-users/zsh-completions.git

# 添加如下配置
fpath=(path/to/zsh-completions/src $fpath)

# 刪除~/.zcompdump文件
rm -f ~/.zcompdump; compinit

vim ~/.zshrc
# 在文件裡找到plugins,添加
plugins=(
  autojump
  zsh-autosuggestions
  zsh-syntax-highlighting
  zsh-completions
)

# 最後
source ~/.zshrc

執行compinit命令的時候,可能回提示如下警告:

zsh compinit: insecure directories

這是權限造成的,執行如下的命令,然後再重新執行compinit命令即可。

sh
chmod go-w '/usr/local/share'

這個命令的意思是修改 /usr/local/share 文件夾的權限,使得此文件夾對組成員用戶和其他用戶不可寫。

進階修改

sh
# 如果粘貼 URL 和其他文本出現混亂,請取消註釋以下行。
DISABLE_MAGIC_FUNCTIONS="true"

# 啟動錯誤命令自動更正
ENABLE_CORRECTION="true"

# 在命令執行的過程中,使用小紅點進行提示
COMPLETION_WAITING_DOTS="true"

最後更新於: