Macbook 開發環境設定大全

Photo by Ben Kolde on Unsplash

Overview

Ref: [[2022-09-10-ipad-setup]]

Challenges 現況 挑戰

  • 每次要設定 macbook 開發環境時, 總是頭痛到底設定了哪些東西跟軟體

Objectives 目標 效益

  • 整理開發環境所需的套件與安裝指令, 方便後續新增查找

KRs 結果 解法

  • 2022-09-10 設定完成
  • 2022-09-17 重置 MacBook Pro 2019 15" i7 16G/256G

Software 軟體

Dev 開發

  • IDE, Editor: Xcode, vscode, sublime text, iTerm2, Fig
  • CI/CD: git, Sourcetree
  • Dev: Python, docker, postman

Office

  • Utils: xtrafinder
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
brew install --cask alfred
brew install --cask rocket
brew install --cask skitch
brew install --cask flux
brew install --cask the-unarchiver
brew install --cask dozer
brew install --cask coconutbattery
brew install --cask mounty
brew install --cask karabiner-elements
brew install --cask tunnelbear
brew install --cask macx-video

Other Mac Setups

  • Trackpad, Accessibility > Pointer Control, Trackpad Options > Enabling Dragging (three finger drag)
  • Keyboard > Shortcuts
    • Input Source: cmd ⌘ + space. 與 spotlight 互換 ctrl ⌃ + space
  • Sharing (Computer Name), Dock (Left)
  • Batter > Battery > disable “Automatic graphics swithting”

Home Folder Structure

1
2
3
4
5
# ~/
dev
  andro
  env
Downloads  

homebrew - macOS 套件管理工具

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
# install homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Run these two commands in your terminal to add Homebrew to your PATH:
# 如果是 M1 的話需要加以下兩個 command. Intel 的不用, /usr/local 本來就在 PATH 了
# https://stackoverflow.com/questions/70983104/brew-installs-not-appearing-in-usr-local-bin
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/androchentw/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"

brew update 
brew upgrade

# https://github.com/Homebrew/brew/issues/3784
# use commands below if you want to delete downloaded caches in ~/Library/Caches/Homebrew
# brew cleanup -n
# brew cleanup
# rm -rf $(brew --cache)

iTerm2 - 點亮 Terminal + Alfred + Fig

iTerm2 shortcuts

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# iTerm2: replacement for Terminal
brew install --cask iterm2

### fig: IDE-style autocomplete for your existing terminal
brew install --cask fig

# Setup shortcuts
# ⌘ ← "SEND HEX CODE" 0x01
# ⌘ → "SEND HEX CODE" 0x05
# ⌥ ← "SEND ESC SEQ"  b
# ⌥ → "SEND ESC SEQ"  f
  • Themes: Nord, JetBrains Darcula, tokyonight-storm

1. zsh

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# 用 homebrew 安裝的 zsh 位置在 /usr/local/bin/zsh
which zsh
# > /bin/zsh
zsh --version
# > zsh 5.8.1 (x86_64-apple-darwin21.0)

brew install zsh
sudo sh -c "echo $(which zsh) >> /etc/shells"
chsh -s $(which zsh)
# restart terminal
which zsh
# > (Intel) /usr/local/bin/zsh
# > (M1) /opt/homebrew/bin/zsh
zsh --version
# > zsh 5.9 (arm-apple-darwin21.3.0)

2. oh-my-zsh: zsh setup management framework

下次再試試看也用 Fig 安裝 oh-my-zsh

1
2
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
# vim ~/.zshrc

3. Nerd font: font package

1
2
3
4
5
6
7
# Nerd font
brew tap homebrew/cask-fonts
brew install --cask font-hack-nerd-font
 
# 為了稍後的 p10k 設定, 要讓 icon 能正常顯示
# iTerm2 > Preferences > Profile > Text > Font > 選 Hack Nerd Font Mono
# https://github.com/romkatv/powerlevel10k/issues/996

4. Powerlevel10k: oh-my-zsh Themes

1
2
3
4
5
# Powerlevel10k
brew install romkatv/powerlevel10k/powerlevel10k
echo "source $(brew --prefix)/opt/powerlevel10k/powerlevel10k.zsh-theme" >> ~/.zshrc
source ~/.zshrc
p10k configure

5. zsh plugins 改用 Fig 安裝 Plugins

Note: 這一塊我在弄的時候有點搞砸了… 但總之最後是通了, 之後有機會 (x) 再回來修

=> 2022-09-17 改先裝 fig (因為 fig 裡也有這些 package), 就不用敲這些指令了! 而且可以用帳號同步, 太方便了

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
git clone --depth 1 -- https://github.com/marlonrichert/zsh-snap.git
source zsh-snap/install.zsh
znap pull
echo "znap source marlonrichert/zsh-autocomplete" >> ~/.zshrc

# https://github.com/zsh-users/zsh-autosuggestions/blob/master/INSTALL.md#oh-my-zsh
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
git clone --depth 1 -- https://github.com/marlonrichert/zsh-autocomplete.git $ZSH_CUSTOM/plugins/zsh-autocomplete

vi ~/.zshrc
# plugins=(git zsh-autosuggestions zsh-autocomplete)

# brew install zsh-autosuggestions
# echo "source $(brew --prefix)/share/zsh-autosuggestions/zsh-autosuggestions.zsh" >> ~/.zshrc 

VS Code 設定 p10k terminal

  • Preferences: Open User Settings JSON (cmd ⌘ + shift + P) 加入以下:
1
2
3
"terminal.external.osxExec": "iTerm2.app",
"terminal.integrated.defaultProfile.osx": "zsh",
"terminal.integrated.fontFamily": "Hack Nerd Font Mono"

vscode extentions

git - 版本控制

1
2
3
4
5
6
# Version control
brew install git
brew install --cask sourcetree

git config --global user.email "[email protected]"
git config --global user.name "androchentw"

python

pyenv + pyenv-virtualenv

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
# This is the recommended method of installation if you installed pyenv with Homebrew.
brew install pyenv-virtualenv
echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.zshrc
            # if which pyenv-virtualenv-init > /dev/null; then eval "$(pyenv virtualenv-init -)"; fi

brew install pyenv
alias brew='env PATH="${PATH//$(pyenv root)\/shims:/}" brew'

echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc
echo 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(pyenv init -)"' >> ~/.zshrc
source ~/.zshrc
exec "$SHELL"

pyenv --version
# > pyenv 2.3.4
pyenv-virtualenv --version
# > /usr/local/bin/pyenv-virtualenv: line 106: pyenv-version-name: command not found
# > /usr/local/bin/pyenv-virtualenv: line 141: pyenv-prefix: command not found
# > pyenv-virtualenv 1.1.5 (virtualenv unknown)

python3 + pip3

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
which python3
# /usr/bin/python3
python3 --version
# Python 3.8.9
# Python 3.9.6
pip3 --version
# pip 20.2.3 from /Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/site-packages/pip (python 3.8)
# pip 21.2.4 from /Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/site-packages/pip (python 3.9)
which pip3
# /usr/bin/pip3

pyenv install --list | grep " 3\.[1]" 
pyenv install 3.10.6 

pyenv global 3.10.6
# restart iTerm2
python3 --version
# Python 3.10.6
pyenv virtualenv 3.10.6 env-3.10.6

# test env-3.10.6 virtualenv settings
mkdir test 
cd test 
pyenv local env-3.10.6
python --version
# Python 3.10.6
cd ..
rm -rf test


brew install python3
# restart iTerm2

which python3
# /Users/androchentw/.pyenv/shims/python3
which pip3
# /Users/androchentw/.pyenv/shims/pip3
pip3 --version
# pip 22.2.1 from /Users/androchentw/.pyenv/versions/3.10.6/lib/python3.10/site-packages/pip (python 3.10)
which python
# /Users/androchentw/.pyenv/shims/python
which pip
# /Users/androchentw/.pyenv/shims/pip
pip --version
# pip 22.2.1 from /Users/androchentw/.pyenv/versions/3.10.6/lib/python3.10/site-packages/pip (python 3.10)

==> /usr/bin occurs before /usr/local/bin This means that system-provided programs will be used instead of those provided by Homebrew. This is an issue if you eg. brew > installed Python.

Consider editing your .bash_profile to put: /usr/local/bin ahead of /usr/bin in your > $PATH.

Backup shell .rc settings

1
2
cat ~/.zshrc > ~/Downloads/2022-andro.zshrc
cat ~/.p10k.zsh > ~/Downloads/2022-andro.p10k.zsh

Others

Murmur

  • 2022-09-09 每次拿到新電腦都要重來一次… 😂

See also