1. 程式人生 > 其它 >zsh 安裝及初始配置

zsh 安裝及初始配置

Zsh安裝及配置

Zsh is a shell designed for interactive use, although it is also a powerful scripting language.

Zsh 安裝

# 檢視當前使用的shell
echo $SHELL
# /bin/bash 預設是bash

# 檢視有哪些shells
cat /etc/shells

# 安裝 zsh
sudo apt-get install zsh -y

# 檢視zsh版本
zsh --version

# 安裝後zsh 後cat /etc/shells 才有/bin/zsh /usr/bin/zsh

# 切換成zsh
chsh -s $(which zsh)
# 或者這條命令
chsh -s /usr/bin/zsh

ohmyzsh 安裝

Oh My Zsh is an open source, community-driven framework for managing your zsh configuration.

# 安裝 ohmyzsh
git clone https://github.com/ohmyzsh/ohmyzsh.git ~/.oh-my-zsh

# 使用預置配置檔案
cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc

Zsh外掛

# 高亮 zsh-syntax-highlighting
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

# 自動提示 zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
# ~/.zshrc
# 啟用外掛
plugins=(
  # 內建外掛,直接填寫啟用即可(選擇)
  # git
  git
  # 根據過往目錄切換記錄快速跳轉
  z
  # 按兩下esc鍵,用sudo許可權
  sudo

  # 記錄歷史輸入的zsh命令,自動提示,快速使用
  zsh-autosuggestions
  # zsh 命令高亮
  zsh-syntax-highlighting
)
# 每次修改了這個`.zshrc`配置檔案,需要過載一下,才能生效。
source ~/.zshrc

# 也可以封裝成一個簡寫命令 alias,這樣每次輸入rl就可以過載
alias rl='source ~/.zshrc'

參考

使用 ohmyzsh 打造 windows、ubuntu、mac 系統高效終端命令列工具 (qq.com)