花十分鐘打造好用的 termianl (iterm2 + zsh + oh-my-zsh + powerlevel10k)

花十分鐘打造好用的 termianl (iterm2 + zsh + oh-my-zsh + powerlevel10k)

簡單花 10 分鐘打造好用 mac terminal 設定
最近因為有電腦重新設定的需求, 而重灌或是使用新電腦的第一件事情通常都會是安裝 terminal 環境, 於是就順手紀錄一下 homebrew, iterm2, zsh 的設定步驟,順便附上 vscode 需要進行對應的設定步驟~

安裝還境:

  • MacOS: Big Sur (11.4)

Install homebrew

Mac 使用這必裝的套件管理工具

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

若安裝時卡在 download command line tools for xcode 只須照著以下步驟更新即可

system preferencesSoftware UpdateMore info 勾選 xcode tool, 並更新,安裝完成後重新執行 homebrew 安裝指令即可

Install iterm2

好用的 Terminal

1
$ brew cask install iterm2

Install zsh

Z shell是一款可用作互動式登入的shell及指令碼編寫的命令直譯器。Zsh對Bourne shell做出了大量改進,同時加入了Bash、ksh及tcsh的某些功能。 (擷取自 wiki)

檢查是否有 zsh, 新版的 MacOS 有內建 zsh 若已經安裝過 zsh 可以跳過此步驟

1
2
3
4
5
# check zsh installation status 
$ which zsh

# modify default shell to zsh.
$ chsh -s $(which zsh)

Install oh-my-zsh

提供 zsh 配置, 主題, 插件 管理功能

1
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

Install zsh theme: powerlevel10k

幫妳的 zsh 換上美觀的主題

1
2
3
4
5
6
7
8
9
10
11
# download zsh theme: powerlevel10k
$ git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k

# update zsh theme
$ vim ~/.zshrc

# update config
ZSH_THEME="powerlevel10k/powerlevel10k"

# refresh terminal
$ exec $SHELL

此時應該會請您進行一些基本外觀設定,依照個人喜好選擇即可

到這裡就完成基本的設定了~

Update VSCode Config (Optional)

若是 VSCode 使用者此時應該會發現當中的 terminal 顯示會怪怪的,必須到 VSCode 中進行簡單的調整,以下擷取自: https://github.com/romkatv/powerlevel10k/issues/671 的分享

假設使用 powerlevel10k 預設的字體只需按照下方設定即可正常顯示

  1. Open Settings in Visual Studio Code.

    • On PC: press  Ctrl+,
    • On Mac: press  Cmd +,
  2. Enter terminal.integrated.fontFamily in the search box at the top of Settings tab and set the value below to MesloLGS NF.

    完成設定後就可以看見 vscode 的 terminal 正常顯示了~

若使用其他的字體必須先下載字體再進行設定可以參照文章的分享設定。

感謝收看

Reference

花十分鐘打造好用的 termianl (iterm2 + zsh + oh-my-zsh + powerlevel10k)

https://ctsai.dev/20211018/mac-iterm2-homebrew-zsh-config/

Author

Mike Tsai

Posted on

2021-10-18

Updated on

2023-09-15

Licensed under

Comments