Windows Git Bash 改用 Zsh
zsh 是一個很好用方便的 shell,在 Linux 安裝非常方便,在 Windows 上如果有安裝 Git,也可以透過 Git Bash 來使用,操作環境可以大幅貼近 Linux。
0. 準備
- 要先裝 Windows Terminal
- 要安裝 Git for Windows
1. 安裝ZSH
Windows
將壓縮檔內容複製到 Git 安裝目錄(一般而言是 C:\Program Files\Git )
2. 安裝 oh-my-zsh
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
3. 修改 ~/.bashrc
Windows 的 user home 路徑是 C:\Users\<user_name>,所以要修改此目錄下的 .bashrc,如果沒有這個檔案就自己新增一個。
然後在 C:\Users\<user_name>\.bashrc 的最後加入:
if [ -t 1 ]; then
exec zsh
fi
這樣下次 bash 啟動的時候就會自動使用 zsh。
zsh 被啟動之後,我們的設定檔就變成了 ~/.zshrc 而不是 ~/.bashrc 了。
4. 安裝字型
等一下要使用的佈景主題會用很多字型裡的符號在UI上,所以一般正常的字型沒辦法顯示,只會看到方框裡面有一個問號。 所以我們要下載「修改過」的字型來顯示這些特殊符號。
到 Nerd Font下載你喜歡的字型。然後安裝到 Windows 裡面。這樣就可以了。
這裡假設你下載了 FiraCode Nerd Font。

5. 設定 Windows Terminal 的字型
打開 Windows Terminal,按 Ctrl+, 進入設定畫面,左邊選 Git Bash ,然後在右邊選 “Appearance”

在 Font Face 那邊選擇 FiraCode Nerd Font。

6. 安裝 powerlevel10k
powerlevel10k 這個佈景主題讓 zsh 變得很好看
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k
然後打開 ~/.zshrc ,把佈景主題改成 powerlevel10k
找到 ZSH_THEME 這一行,改成 ZSH_THEME="powerlevel10k/powerlevel10k"

然後重新打開 Windows Terminal,打開 Git Bash ,就會出現 powerlevel10k 的 config 流程,你可以在這裡設定自己喜歡的風格樣式。
如果字型設定正確的話,會看到正確的符號,否則就是方框裡面有一個問號。

7. 安裝 plugin
這步不一定要做,看需求。
安裝 zsh-syntax-highlighting
這個 plugin 可以在 terminal 顯示 highlight syntax 安裝
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
然後要修改 ~/.zshrc,在 plugins 加入 zsh-syntax-highlighting

安裝 zsh-autosuggestions
這個 plugin 可以在輸入的時候提供已經輸入過的歷史命令或是相似的命令,讓你節省一點時間。 安裝
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
然後修改 ~/.zshrc,在 plugins 加入 zsh-autosuggestions 。
