Add '2026-01-16_Windows Git Bash 改用 Zsh'
|
After Width: | Height: | Size: 24 KiB |
|
After Width: | Height: | Size: 126 KiB |
|
After Width: | Height: | Size: 195 KiB |
|
After Width: | Height: | Size: 131 KiB |
|
After Width: | Height: | Size: 251 KiB |
|
After Width: | Height: | Size: 265 KiB |
|
After Width: | Height: | Size: 187 KiB |
|
After Width: | Height: | Size: 209 KiB |
116
content/posts/2026/2026-01-16_Windows Git Bash 改用 Zsh/index.md
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
---
|
||||||
|
slug: Windows Git Bash 改用 Zsh
|
||||||
|
title: Windows Git Bash 改用 Zsh
|
||||||
|
description:
|
||||||
|
toc: true
|
||||||
|
authors: []
|
||||||
|
tags: []
|
||||||
|
categories: []
|
||||||
|
series: []
|
||||||
|
date: 2026-01-16T00:00:00
|
||||||
|
lastmod: 2026-01-16T00:00:00
|
||||||
|
featuredVideo:
|
||||||
|
featuredImage:
|
||||||
|
draft: false
|
||||||
|
enableComment: true
|
||||||
|
---
|
||||||
|
[zsh](https://zh.wikipedia.org/zh-tw/Z_shell) 是一個很好用方便的 shell,在 Linux 安裝非常方便,在 Windows 上如果有安裝 Git,也可以透過 Git Bash 來使用,操作環境可以大幅貼近 Linux。
|
||||||
|
|
||||||
|
<!--more-->
|
||||||
|
|
||||||
|
## 0. 準備
|
||||||
|
|
||||||
|
- 要先裝 [Windows Terminal](https://apps.microsoft.com/detail/9n0dx20hk701?hl=zh-TW&gl=TW)
|
||||||
|
- 要安裝 [Git for Windows](https://git-scm.com/install/windows)
|
||||||
|
|
||||||
|
## 1. 安裝ZSH
|
||||||
|
|
||||||
|
### Windows
|
||||||
|
|
||||||
|
到 [Msys2 Package: zsh](https://packages.msys2.org/packages/zsh?repo=msys&variant=x86_64)下載
|
||||||
|

|
||||||
|
|
||||||
|
將壓縮檔內容複製到 Git 安裝目錄(一般而言是 `C:\Program Files\Git` )
|
||||||
|
|
||||||
|
## 2. [安裝 oh-my-zsh](https://ohmyz.sh/)
|
||||||
|
|
||||||
|
```shell
|
||||||
|
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](https://www.nerdfonts.com/)下載你喜歡的字型。然後安裝到 Windows 裡面。這樣就可以了。
|
||||||
|
這裡假設你下載了 FiraCode Nerd Font。
|
||||||
|

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

|
||||||
|
|
||||||
|
在 Font Face 那邊選擇 FiraCode Nerd Font。
|
||||||
|

|
||||||
|
|
||||||
|
|
||||||
|
## 6. 安裝 [powerlevel10k](https://github.com/romkatv/powerlevel10k)
|
||||||
|
|
||||||
|
[powerlevel10k](https://github.com/romkatv/powerlevel10k) 這個佈景主題讓 zsh 變得很好看
|
||||||
|
|
||||||
|
```shell
|
||||||
|
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](https://github.com/zsh-users/zsh-syntax-highlighting)
|
||||||
|
|
||||||
|
這個 plugin 可以在 terminal 顯示 highlight syntax
|
||||||
|
安裝
|
||||||
|
|
||||||
|
```shell
|
||||||
|
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](https://github.com/zsh-users/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` 。
|
||||||