跳至主要内容

macOS 環境設定

· 閱讀時間約 3 分鐘
Vincent Chi

目前主力工作環境是 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
  • font-hack-nerd-font:用於與 lsd 相互搭配

ZSH

其它

開發工具

瀏覽器

社交

其它

設定

SSH

因為採用 1Password 管理 SSH Key,以下設定直接套用 1Password SSH Client 設定

# ~/.ssh/config
Host *
IdentityAgent "~/Library/Group Containers/2BUA8C4S2C.com.1password/t/agent.sock"
  • 加入 Keychain Access:eval "$(ssh-agent -s)"; ssh-add -K ~/.ssh/id_ed25519

Git

  • 加入 .gitignore_global
# ~/.gitignore_global

# Created by https://www.toptal.com/developers/gitignore/api/macos
# Edit at https://www.toptal.com/developers/gitignore?templates=macos

### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

# End of https://www.toptal.com/developers/gitignore/api/macos
  • 設定 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 --"
git config --global core.excludesFile ~/.gitignore_global