Try   HackMD

改變Macbook Terminal的樣式

自己剛入手一台Macbook air M2,這是我第一台使用蘋果電腦,因為工作關係會常常使用終端機做事情,所以希望terminal的樣貌可以好看一點或是有一些特殊的功能可以讓我做事更方便。
我知道內建terminal可以更改基本的顏色跟字型大小樣式,就如同下面那張圖所示(上網抓的),但使用功能還是有限制。

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

特地建立筆記,裡頭包括上網看別人的教學以及在安裝過程中遇到問題而又如何解決。下面是改變後的樣子

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

實際操作

1. 安裝Homebrew

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

第一件事,就是安裝brew套件到mac。
幸運的話只要在terminal打入以下指令就可以安裝成功。

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

要確保有安裝到Homebrew,打入以下指令。

brew --version

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

若出現Homebrew 4.1.xx就代表安裝成功,但最一開始我是出現zsh: command not found: brew,後來發現應該是 zsh 的 PATH 環境變數沒有包含 Homebrew 的安裝路徑。以下是詳細的解決資訊

  1. 把Homebrew安裝路徑加到zshrc
echo "export PATH=/opt/homebrew/bin:$PATH" >> ~/.zshrc
  1. Homebrew重新檢測問題並修復
brew doctor
  1. 重新輸入brew --version就成功了

2. 安裝iTerm2

在terminal輸入以下指令,等安裝完就可以看到app已經在電腦的applications中了。

brew install --cask iterm2

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

打開iTerm,並按command+i,就會出現Preferences視窗,裡頭就可以調各種顏色及字型。(記得要把自己設定好的視窗設成預設的,不然重開iTerm會回到原本系統預設的樣式)

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

如果覺得原本iTerm的顏色好少,可以去Gitlab下載下面的zip檔iTerm2-Color-Schemes

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

並在preferences>Colors>Color Presets>Import,把從Github下載的檔案,選到schemes,裡面就有各種的樣式供自己挑選。→若要看實體顏色可以去Github的README.md

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

3. 安裝Oh My ZSH

已經把Iterm2下載好後,接著就是去下載Oh My Zsh,有很多好用的plugins可以使用,能夠依照自己喜歡的去決定要加入什麼樣的功能。

下面是官網對於Oh My Zsh的介紹

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

在terminal打入以下指令,可以在官網首頁的下面找到,有兩種install方式,我是用curl。

sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

完成後,在terminal可以看到有一個大大的用彩虹顏色所得出的Oh My Zsh

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

接下來就是來更改.zshrc檔,加入自己喜歡的plugins。去磁碟機按下去,可以看到僅有少少的幾個資料夾,要顯示隱藏的資料夾,只要按command+shift+.,就能顯示了。

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

點去User>使用者>.zshrc就可以更改檔案。
像我改了幾個地方

  • ZSH_THEME,像我自己就不太喜歡random,怕太多顏色會搞混,所以就設成我自己喜歡的樣式。要看更多樣式,可以去ohmyzsh Theme挑選

    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →

  • plugins,Github上有每一個功能的解說,依照自己工作需要用到的就可以加進去。

    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →

    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →

  • alias像是打zshconfig就會幫我把.zshrc的檔案打開,不用慢慢點進去。打code就會自洞開VScode。

    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →

解決BUG

  • 雖然iterm2運作都正常,但發現在開啟macbook原始的terminal會出現亂碼、在Vscode的terminal也是。→出現該問題的原因是因為字體沒有一致。把terminal的字體全都改成一樣就解決了
    先去看iterm2所設定的字體

    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →

    1. 原始terminal
      打開terminal並在Profiles→Text→Font更改字體

      Image Not Showing Possible Reasons
      • The image was uploaded to a note which you don't have access to
      • The note which the image was originally uploaded to has been deleted
      Learn More →

    2. VScode
      按左下角的settings圖示,並在搜尋框打terminal font在Font Family打上字體樣式

      Image Not Showing Possible Reasons
      • The image was uploaded to a note which you don't have access to
      • The note which the image was originally uploaded to has been deleted
      Learn More →