跳至主要内容

macOS 環境設定

· 閱讀時間約 4 分鐘
Vincent Chi
Software Enineer, Backend

目前主力工作環境是 macOS,用這篇文章記錄一下從無到有設定整個 macOS 的流程。

硬體

  • Macbook Pro 2023 14"
  • CPU: Apple M2 Pro
  • RAM: 32GB
  • SSD: 512GB

經過一、兩年的觀望,目前認為 M 系列晶片在生態上已經趨於穩定,所以在 2023 年把原本手上的末代 Intel Macbook Pro 出掉更換了 M2 Pro 的設備。

這次考量到攜帶的方便性,選擇了 14" 而非之前的 16",加上預算的限制所以用 M2 Pro 而非 M2 Max。

軟體

  • Homebrew:不必解釋,必裝的套件管理器

Homebrew

  • 開發:vim, git
  • 網路:curl, wget
  • GNU Tools:coreutils, findutils, gnu-tar, gnu-sed, gawk, gnutls, gnu-getopt, grep
  • 程式語言:nodejs, go, rust, python
  • 其它:zsh, lsd, jq, htop, fzf

因為用不慣 macOS 自帶的一些指令(可能是因為授權的緣故,macOS 內建的指令版本都舊很多),所以我通常會重新安裝 GNU Tools。

需要注意的是,如果要讓 GNU Tools 的指令取代原本的指令,需要在 .bashrc.zshrc 中加入以下內容

export PATH="/opt/homebrew/opt/curl/bin:$PATH"
export PATH="/opt/homebrew/opt/gnu-tar/libexec/gnubin:$PATH"
export PATH="/opt/homebrew/opt/gnu-sed/libexec/gnubin:$PATH"
export PATH="/opt/homebrew/opt/gawk/libexec/gnubin:$PATH"
export PATH="/opt/homebrew/opt/gnu-getopt/bin:$PATH"
export PATH="/opt/homebrew/opt/grep/libexec/gnubin:$PATH"
export PATH="$HOME/.local/bin:$PATH"

alias ls="lsd"
alias python="python3"

Homebrew Cask

  • squirrel:Rime 輸入法,用於實現嘸蝦米輸入法的引擎

通常會建議不要使用 Homebrew Cask 安裝會自動更新的軟體(如 Visual Studio Code 或 Microsoft Edge 等),這是因為 Homebrew 的 Upgrade 指令可能會與內建的自動更新互相衝突。

Homebrew Fonts

  • font-jetbrains-mono

其它

開發工具

瀏覽器

社交

設定

SSH

目前採用 1Password 管理多個 GitHub 帳戶,以下是我的設定流程

  1. 在 1Password 分別下載 main.pubother.pub,並放入 ~/.ssh/
  2. 修改 ~/.ssh/config
Host *
IdentityAgent "~/Library/Group Containers/2BUA8C4S2C.com.1password/t/agent.sock"
IdentityFile ~/.ssh/main.pub
IdentitiesOnly yes

Host other.git
HostName github.com
User git
IdentityFile ~/.ssh/other.pub
IdentitiesOnly yes

Git

  • 加入 .gitignore_global
wget -O $HOME/.gitignore_global https://www.toptal.com/developers/gitignore/api/macos && \
git config --global core.excludesFile ~/.gitignore_global
  • 設定 git
git config --global color.ui true && \
git config --global core.editor vim && \
git config --global alias.co commit && \
git config --global alias.lg "log --color --graph --all --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --"
  • 為特定資料夾設定不同的 gitconfig

因為存在多個不同的 GitHub 帳號,為了使 Signing Key 能夠共用所以需要在

~/.gitconfig
# ...
[includeIf "gitdir:~/other/"]
path = ~/other/.gitconfig
~/other/.gitconfig
[user]
email = <Emali>
name = <Name>
signingkey = <SSH Public Key>
[gpg]
format = ssh
[gpg "ssh"]
program = /Applications/1Password.app/Contents/MacOS/op-ssh-sign
[commit]
gpgsign = true