257 - 《如何从 0 开始配置 MacBook Pro》

发布于 2023年2月7日

昨天新的 MBP 终于到了,要从 0 开始配置成趁手的还是需要一些时间的,我总共花了 4 小时左右。在此记录下,希望对大家有所帮助,这可以算是「装了啥」的详细版。如果我基于这篇文章再来一遍,应该可以减少到 2 小时以下。但是,应该不会再来一次了,自己的电脑走 TimeMachine 就好了。

视频版见 https://www.bilibili.com/video/BV1e14y1c7aJ/

安装 ClashX,你懂的

略。

安装 App 和 Cli 工具

1、安装 HomeBrew 并用他安装 App 和 Cli 工具。App 可以在 homebrew-cask — Homebrew Formulae 里找有没有,Cli 工具可以在 homebrew-core — Homebrew Formulae 找有没有。

# 先开代理,不然会很慢(依赖第一步)
export https_proxy=http://127.0.0.1:7890 http_proxy=http://127.0.0.1:7890 all_proxy=socks5://127.0.0.1:7890

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

# 用 HomeBrew 安装 App,以下是我可以用 HomeBrew 安装的 App 列表(以字母排序,方便你查找)
brew install --cask \
  115browser \
  1password \
  alfred \
  anki \
  battery-buddy \
  coteditor \
  docker \
  eagle \
  espanso \
  figma \
  google-chrome \
  gas-mask \
  handbrake \
  iina \
  iterm2 \
  karabiner-elements \
  keepingyouawake \
  keka \
  keycastr \
  licecap \
  microsoft-edge \
  microsoft-remote-desktop \
  ngrok \
  obs \
  obsidian \
  qq \
  setapp \
  shottr \
  sogouinput \
  sourcetree \
  telegram \
  thor \
  usr-sse2-rdm \
  videofusion \
  visual-studio-code \
  wechat \
  webstorm \
  zerotier-one

# 安装 Cli 工具,以下是我的(以字母排序,方便你查找)
brew install \
  autojump \
  bat \
  cmatrix \
  commitzen \
  deno \
  diff-so-fancy \
  fd \
  ffmpeg \
  fzf \
  gh \
  git \
  httpie \
  hub \
  hyperfine \
  imagemagick \
  jq \
  lazygit \
  mkcert \  
  nvm \
  pnpm \
  the_silver_searcher \
  tig \
  tldr \
  tree \
  ugit \
  wget

2、用 SetApp 安装额外 App。

  • Bartender
  • CleanMyMac X
  • CleanShot X
  • DevUtils
  • Downie
  • Focus
  • Sip
  • TablePlus
  • RapidAPI
  • Paste
  • Yoink

3、用 Mac App Store 安装额外 App。

  • Bob
  • Tot
  • RunCat
  • Infuse

4、通过其他渠道安装额外 App。

准备本地目录

我在 ~/Documents 下建了两个目录(新电脑还没施工完成,这里还会补充更多目录),Code 和 SoftwareConfiguration,长这样。Code 用于存代码;SoftwareConfiguration 用于保存各种软件配置,我把 Alfred、Eagle 和 Espanso 的配置放在这里。

配置 App

按这个顺序会比较好。

1、Karabiner-Elements

参考 Karabiner-Element 配置 F19 键 - HackMD 。在 Karabiner-Elements complex_modifications rules 搜「Change caps_lock key」,import 后只保留一条和 F19 相关的,然后在命令行里编辑「~/.config/karabiner/karabiner.json」,把刚才那条规则的「caps_lock」换成「right_command」(两处)。这样你就把基本不会用到的「右⌘」废物利用变成了「F19」键,然后你的快捷键组合会多很多。

如果你仔细看配置,会发现「F19」是由四个键「⌘⇧⌃⌥」组成的,在一些 App 的快捷键配置里你会看到四个键,不要奇怪,这也是他。

2、Alfred

做几个配置。1)开启 Powerpack,2)修改快捷键为刚才配的「F19」,3)把老电脑的 Alfred 配置复制到 ~/Documents/SoftwareConfiguration/Alfred 下,然后在「Advanced」里修改配置目录指向他,你的 Workflow 就全回来了,4)「Features > Web Bookmarks」里记得把「Google Chrome Bookmarks」选上,这样就可以用 Alfred 模糊搜 Chrome 书签,用于快速打开网站。

3、iTerm2 和 zsh

先配置 iTerm2,这是效果图。1)Appearance 里,General 的 Theme 选「Minimal」,Pane 里不要「Show per-pane title bar with split panes」,Dimming 里选上第一和第三个,2)Profiles 里,Working Directory 里选「Reuse previous session’s directory」。

安装 zsh 和 starship,starship 是 rust 写的 prompt 工具,极快。

sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
omz update
source ~/.zshrc
# starship 是 rust 写的 prompt 工具,极快
brew install starship
echo 'eval "$(starship init zsh)"' >> ~/.zshrc

安装 zsh 的插件,我个人用到了 zsh-autosuggestions、zsh-completions 和 fast-syntax-highlighting。

git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-completions ${ZSH_CUSTOM:-${ZSH:-~/.oh-my-zsh}/custom}/plugins/zsh-completions
git clone https://github.com/zdharma-continuum/fast-syntax-highlighting.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/fast-syntax-highlighting

配置 ~/.zshrc,我的配置如下(略做删减)。这里有些 alias 是以 , 开头的,因为这样你敲 , 然后按「Tab」就可以看到所有自己定义的命令了。为啥有些没有加 , ?历史原因… 因为其他都用习惯了就不改了。

# Disable brew auto update
export HOMEBREW_NO_AUTO_UPDATE=1
export ZSH="$HOME/.oh-my-zsh"

plugins=(
  # 不会 git 插件,因为和我的 alias 设置冲突
  # git
  zsh-completions
  zsh-autosuggestions
  fast-syntax-highlighting
)

# Alias
alias ,ms="%PATH/TO/MY/SCRIPT%"
alias ,ip="ipconfig getifaddr en0"
alias ,sshconfig="vim ~/.ssh/config"
alias ,gitconfig="vim ~/.gitconfig"
alias b=",ms branch"
alias umi="/Users/%MY_USERNAME%/Documents/Code/github.com/umijs/umi/packages/umi/bin/umi.js"
# chore
alias br="bun run"
alias c='code .'
alias i='webstorm .'
alias cdtmp='cd `mktemp -d /tmp/sorrycc-XXXXXX`'
alias pi="echo 'Pinging Baidu' && ping www.baidu.com"
alias ip="ipconfig getifaddr en0 && ipconfig getifaddr en1"
alias cip="curl cip.cc"
alias qr='qrcode-terminal'
alias ee="stree"
alias hosts="vi /etc/hosts"
## system
alias showFiles="defaults write com.apple.finder AppleShowAllFiles YES && killall Finder"
alias hideFiles="defaults write com.apple.finder AppleShowAllFiles NO && killall Finder"
# cd
alias ..='cd ../'
alias ...='cd ../../'
alias ..l.='cd ../../ && ll'
alias ....='cd ../../../'
alias ~="cd ~"
alias -- -="cd -"
alias ll='ls -alhG'
alias ls='ls -G'
# git
alias git=hub
alias gp="git push"
alias gt="git status -sb"
alias ga="git add ."
alias gc="git commit -av"
alias gcr="git checkout master && git fetch && git rebase"
alias gclean="git reset --hard && git clean -df"
alias grebase="git fetch && git rebase -i"

## timelapse
## ref: https://www.reddit.com/r/mac/comments/wshn4/another_way_to_timelapse_record_your_mac_screen/
function record() {
  cd ~/screencapture/jpg;
  RES_WIDTH=$(/usr/sbin/system_profiler SPDisplaysDataType | grep Resolution);
  RES_WIDTH=(${RES_WIDTH:22:4});
  RES_WIDTH=$((RES_WIDTH/2));
  while :
  NOW=$(date +"%y%m%d%H%M%S");
  do screencapture -C -t jpg -x ~/screencapture/jpg/$NOW.jpg;
    sleep 7 & pid=$!
    NOW=$(date +"%y%m%d%H%M%S");
    wait $pid
  done
}
function

内容预览已结束

此内容需要会员权限。请先登录以查看完整内容。