在 Windows Git Bash 中安裝 bash-git-prompt

Alexee發表於2019-02-16

需求

我經常會在專案根目錄中右鍵點開 Git Bash 進行一些命令列操作,預設視窗中會顯示當前檔案目錄和 git 分支名,但我希望能看到更多資訊,如是否存在未提交的修改、未推送的提交等,這樣我在每天開啟 bash 視窗後就能對當前專案的狀態有個大概的瞭解。

搜尋

我在網上查閱了一番,最終決定使用 bash-git-prompt

結果

先放上最終的效果對比圖:
預設視窗預設視窗
安裝 bash-git-prompt安裝 bash-git-prompt 後

相關含義如下(詳情檢視 bash-git-prompt 官方說明):

(master↑3|✚1): on branch master, ahead of remote by 3 commits, 1 file changed but not staged
(status|●2): on branch status, 2 files staged
(master|✚7…): on branch master, 7 files changed, some files untracked
(master|✖2✚3): on branch master, 2 conflicts, 3 files changed
(master|⚑2): on branch master, 2 stash entries
(experimental↓2↑3|✔): on branch experimental; your branch has diverged by 3 commits, remote by 2 commits; the repository is otherwise clean
(:70c2952|✔): not on any branch; parent commit has hash 70c2952; the repository is otherwise clean

實現

找到你安裝 Git 的地址,在 Git/etc 目錄下將 bash-git-prompt 專案 clone 下來:

git clone https://github.com/magicmonty/bash-git-prompt.git

然後用編輯器開啟 Git/etc 目錄下的 bash.bashrc 檔案,註釋其中全部程式碼,新增如下三行程式碼:

GIT_PROMPT_ONLY_IN_REPO=1
GIT_PROMPT_THEME=Evermeet  # 主題可以自己選,在 Gitetc.bash-git-prompt	hemes 中挑一個
source /etc/.bash-git-prompt/gitprompt.sh

儲存檔案後,重新開啟 Git Bash 視窗,Voila!安裝好了~

問題

如果你發現視窗中的打勾和箭頭等符號顯示有問題,可以這樣做:
右鍵視窗標題欄 -> Options -> Text -> Font Select -> DejaVu Sans Mono

參考Strange character

The font limitation shows up in the default Ubuntu shell on Windows 10 as well but I was able to see the glyph characters by simply using DejaVu Mono https://dejavu-fonts.github.io/.
What @scotlynhatt means is download the font on windows, install it and then select it from the font menu for the WSL window (right click on the title bar -> properties -> font).

相關文章