Skip to main content

ZSH 配置與好用的工具

· 4 min read
Charles Wang
DevOps / Backend Engineer

先前的文章有介紹如何在Windows WSL 內安裝Oh My Zsh 與Powerlevel10k, 還沒設定的請移步到Windows Terminal 搭配WSL

這裡會再延伸說明Oh My Zsh 下有什麼方便好用的工具

ZSH-Autosuggestions​

  • 參考官方文件

  • Clone this repository into $ZSH_CUSTOM/plugins (by default ~/.oh-my-zsh/custom/plugins)

git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
  • Add the plugin to the list of plugins for Oh My Zsh to load (inside ~/.zshrc):
plugins=(
# other plugins...
zsh-autosuggestions
)
  • Refresh ~/.zshrc
source ~/.zshrc

ZSH-Syntax-Highlighting​

  • 參考官方文件

  • Clone this repository in oh-my-zsh's plugins directory:

git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
  • Activate the plugin in ~/.zshrc:
plugins=( [plugins...] zsh-syntax-highlighting)
  • Refresh ~/.zshrc
source ~/.zshrc

ZSH-Completions​

  • 參考官方文件

  • Clone the repository inside your oh-my-zsh repo:

git clone https://github.com/zsh-users/zsh-completions ${ZSH_CUSTOM:=~/.oh-my-zsh/custom}/plugins/zsh-completions
  • Enable it in your .zshrc by adding it to your plugin list and reloading the completion:
plugins=(… zsh-completions)

# 加入到~/.zshrc 的最後一行
autoload -U compinit && compinit
  • Refresh ~/.zshrc
source ~/.zshrc

Homebrew for Linux​

sudo apt install -y curl

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"' >> $HOME/.zshrc

eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"

sudo apt-get install build-essential

brew install gcc

其它工作需求工具​

Git​

sudo apt-get update && sudo apt-get upgrade -y

sudo apt-get install git-core

git config --global user.name "$USER_NAME"

git config --global user.email "$USER_EMAIL"

Docker Engine​

curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
sudo usermod -aG docker $USER_NAME
  • Logout or Reboot

Google Cloud SDK​

echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list

sudo apt-get install apt-transport-https ca-certificates gnupg

curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key --keyring /usr/share/keyrings/cloud.google.gpg add -

sudo apt-get update && sudo apt-get install google-cloud-sdk

Kubectl​

  • 如果先裝好Google Cloud SDK
sudo apt-get install kubectl

Kubectx​

sudo git clone https://github.com/ahmetb/kubectx /opt/kubectx

sudo ln -s /opt/kubectx/kubectx /usr/local/bin/kubectx

sudo ln -s /opt/kubectx/kubens /usr/local/bin/kubens
  • 套用到Oh-My-Zsh 的zsh-completions
mkdir -p ~/.oh-my-zsh/completions

chmod -R 755 ~/.oh-my-zsh/completions

ln -s /opt/kubectx/completion/kubectx.zsh ~/.oh-my-zsh/completions/_kubectx.zsh

ln -s /opt/kubectx/completion/kubens.zsh ~/.oh-my-zsh/completions/_kubens.zsh
  • 如果已經設定好zsh-completions
source ~/.zshrc

Nodejs​

# Using Ubuntu
curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -

sudo apt-get install -y nodejs
  • Node.js v14.x
# Using Ubuntu
curl -fsSL https://deb.nodesource.com/setup_14.x | sudo -E bash -

sudo apt-get install -y nodejs
  • Node.js v12.x
# Using Ubuntu
curl -fsSL https://deb.nodesource.com/setup_12.x | sudo -E bash -

sudo apt-get install -y nodejs
  • Node.js LTS
# Using Ubuntu
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt-get install -y nodejs

Hexo​

  • 參考官方文件

  • 如果已經安裝好Git, Node.js v12.x

npm install -g hexo-cli

Terraform CLI​

  • 如果已經安裝好Homebrew for Linux
brew install terraform

K9S​

  • 如果已經安裝好Homebrew for Linux
brew install k9s