tags: MacOS
、Warp
、Powerlevel10k
、terminal
、productivity
客製化 Terminal - Warp + Powerlevel10k
身為一位工程師,日常都需要跟指令列打交道,加上筆者是微顏控,需要有美美的 command line 環境,所以對 Terminal 選擇有點挑剔,轉換成 Warp 前,是使用 iTerms2 + oh-my-zsh,調成喜歡的樣式。
Warp 預設樣式已經有個 70 分,highlight 等配色都很舒服,加上強大其他功能,如果對介面沒特別要求,基本就開箱即用。
但對於用習慣 iTerms2 樣式和設定,Warp 預設已經滿足不了筆者了,手邊公司電腦有參考 How to Configure Starship to Look Exactly Like P10K 做設定,結果也是挺滿意的,但因為 iterms2 的關係, zsh config 留有 Powerlevel10k 相關設定,每次只要開啟 Warp,最上方的 prompt 就會一直跳出不支援 Powerlevel10k 提示,有點擾人 (後來發現可在 .zshrc
檔案中,寫 Terminal 判斷,去關掉提示)。
好消息是新版本 (v0.2023.06.20.08.04) 的 Warp,可以支援 Powerlevel10k 了!剛好趁這次機會幫自己的電腦設定一下 Warp 樣式。
安裝 warp
$brew install --cask warp
設定字體
Settings
-> Appearance
-> Text
-> Terminal font
改成 MesloGS NF
💡補充:
如果電腦中沒有 MesloGS NF
字體,請至 Manual font installation 下載,否則部分 icon 會無法正確顯示。
打開 PS1 選項
Settings
-> Feature
-> Session
-> 打開 Honor user's custom prompt(PS1)
安裝 powerlevel10k
$git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ~/powerlevel10k
echo 'source ~/powerlevel10k/powerlevel10k.zsh-theme' >>~/.zshrc
如果之前有安裝過,記得 pull 最新版本,可參考 p10k repo。
修改 zsh 主題 (zsh theme)
$vim ~/.zshrc
找到 ZSH_THEME="robbyrussell"
這行,先輸入 i
進入 insert 模式,將 robbyrussell
改為 powerlevel10k/powerlevel10k
,按 esc
結束編輯,輸入 wq
,存檔離開。
...
## 修改 theme 的名稱為 powerlevel10k/powerlevel10k
ZSH_THEME="powerlevel10k/powerlevel10k"
...
修改完後,重新執行 .zshrc
設定檔:
source ~/.zshrc
設定 p10k config
接下來會有一系列 icon 有無正常顯示問題和 command line 樣式設定,依實際情況和需求回答即可。
筆者設定參考
因為之前已在 iTerm2 那邊設定過 p10k
config 了,所以再輸入完 exec zsh
,就直接顯示當初設定的樣式了,附上當時 iTerm2 設定選項供參考。
Q1. Prompt Style?
(3) Rainbow.
Q2. Character Set?(1) Unicode.
Q3. Show current time?(2) 24-hour format.
Q4. Prompt Separators?(1) Angled.
Q5. Prompt Heads?(1) Sharp.
Q6. Prompt Tails?(1) Flat.
Q7. Prompt Height?(1) One line.
Q8. Prompt Spacing?(1) Compact.
Q9. Icons?(2) Many icons.
Q10. Prompt Flow?(1) Concise.
Q11. Enable Transient Prompt?(n) No.
Q12. Instant Prompt Mode?(1) Verbose (recommended).
Q13. Apply changes to ~/.zshrc?y
有需要再調整 p10k prompt,可以輸入:
$vi ~/.p10k.zsh
修改 Warp 的 theme
Warp 預設提供主題很少,如果要客製化主題,可以到 theme repository 挑選喜歡的主題,更多主題設定可以參考 Custom Themes。
Step 1. 新增 themes 資料夾
$mkdir -p ~/.warp/themes/
進入剛建立的 themes 資料夾:
$cd ~/.warp/themes/
Step 2. 新增 theme yaml
再建立一個主題的資料夾,依據自己選擇命名,筆者是選擇 tomorrow-night-eighties
:
# mkdir <theme-folder-name>
$mkdir tomorrow-night-eighties
# cd <theme-folder-name>
$cd tomorrow-night-eighties
編輯 yaml 設定:
# vi <theme-folder-name>
$vi tomorrow-night-eighties.yaml
再將 tomorrow-night-eighties
內容複製到 terminal 後,輸入 :wq
accent: "#6699cc"
background: "#2d2d2d"
details: darker
foreground: "#cccccc"
terminal_colors:
bright:
black: "#999999"
blue: "#b4b7b4"
cyan: "#a3685a"
green: "#393939"
magenta: "#e0e0e0"
red: "#f99157"
white: "#ffffff"
yellow: "#515151"
normal:
black: "#2d2d2d"
blue: "#6699cc"
cyan: "#66cccc"
green: "#99cc99"
magenta: "#cc99cc"
red: "#f2777a"
white: "#cccccc"
yellow: "#ffcc66"
Step 3. 重啟 warp
如果主題沒有套用,請手動至 Appearance
-> 點選 Current theme
-> 選擇剛剛建立的主題。
⚠️ 注意:
設定到這邊,筆者有遇到三個問題,有踩到坑的人可以參考下方解答~
問題一:Operation not permitted
如果下指令有遇到 .: Operation not permitted
或者 git 資訊無顯示,要去 Settings 打開 Files and Folders
權限。
問題二: prompt 的顏色和形狀,顯示會不一致
但同一套設定檔案在 iTerms 是正常的,Warp 這邊會三角形明顯顏色不一樣:
解法是到 Appearance
-> Enforce minimum contrast
改成 Never
,調整完後,顏色顯示就會一致了。
相關 issue 討論:
問題三: cursor 在 Warp 會直接跳新的一行,但其他 Terminal 會接續在原行
不介意的話可忽略該問題,很介意就 run exec zsh
可以解決,但就會無法擁有 multiple cursors、completions 等 Warp 提供的功能。
相關 issue 討論:
結語
Starship 或 Powerlevel10k 都需要花一些時間來設定,中間還踩了一些雷,但最後看到繽紛的 Terminal 就覺得值得了!
之前幫其他同事用他的電腦 debug 的時候,terminal 文字沒有 highlight,整片 log 都是白字,看著微痛苦 XD,立馬推坑他安裝 Warp,就算不客製 command line,預設樣式就屌打原本的了,又有各種提示,直接 Warp 信徒加一,希望這篇有機會推坑更多人進 Warp。