使用iCloud共享的配置文件快速配置新Mac電腦
本文我們介紹如何利用iCloud共享的配置文件來快速配置一臺(tái)新的Mac電腦,以此實(shí)現(xiàn)多臺(tái)電腦分享同一套配置的目的。

準(zhǔn)備工作
- 需要Apple iCloud的支持
- iCloud Drive中已經(jīng)存有以下軟件的配置文件或目錄
工具列表
設(shè)置iCloud
環(huán)境相關(guān)的配置文件我基本上都放在iCloud Drive中,使用iCloud的同步功能,配置文件可以保存在云端,也可以共享給多個(gè)Mac電腦使用。
登陸iCloud,并關(guān)閉iCloud Drive的 Optimise Mac Storage功能。然后我們等待所有的iCloud文件同步到新Mac上。

軟件的安裝
- 安裝Homebrew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
安裝成功的驗(yàn)證命令:
brew -v
Homebrew 2.1.2
Homebrew/homebrew-core (git revision cf0a; last commit 2019-05-18)
Homebrew/homebrew-cask (git revision 0e4c0; last commit 2019-05-18)
- 使用Homebrew安裝基本的環(huán)境(brew安裝軟件可任選,我把我的所有HomeBrew軟件都羅列于此)
因?yàn)橛行┸浖枰止ぽ斎氘?dāng)前賬戶的密碼,建議一個(gè)個(gè)軟件安裝下去
xcode-select --install
brew install gcc
brew install libuv
brew install zsh zsh-completions autojump zsh-syntax-highlighting
brew cask install wireshark
brew install postgresql
brew tap theory/sqitch
brew install sqitch_pg
brew install sqitch --with-postgres-support
brew install wget
brew cask install visual-studio-code
brew cask install iterm2
brew cask install appcleaner
brew install caskroom/cask/brew-cask
# brew tap caskroom/versions
brew cask install sublime-text
brew tap caskroom/fonts
brew cask install font-inconsolata font-menlo-for-powerline font-meslo-for-powerline
brew install terraform
brew install packer
brew install ansible
brew cask install virtualbox
brew cask install vagrant
brew cask install vagrant-manager
brew cask install typora
brew cask install github
brew install autossh
brew install jq
brew install gnu-sed
brew install mysql
brew install pre-commit
brew install certbot
brew install tig
brew cask install dash
brew cask install shortcat
brew cask install google-cloud-sdk
brew cask install docker
brew cask install google-chrome
brew cask install firefox
brew cask install qlcolorcode qlstephen qlmarkdown quicklook-json webpquicklook suspicious-package quicklookase qlvideo
brew install sonar-scanner
brew cask install dash
brew cask install alfred
brew cask install vault # hashicorp vault
brew install kubernetes-helm
配置iterm2
- 第一次打開Iterm2,軟件會(huì)提示需要給
Full Disk Access權(quán)限,請(qǐng)前往”Security & Privacy”中心進(jìn)行授權(quán)。
iterm2.gif
- 從iCloud Drive中恢復(fù)(設(shè)置)默認(rèn)配置文件
再次打開iTerm2,打開preferences定位到General. 找到頁面最底部的 “Load preferences from a custom folder or URL”. 選擇此選項(xiàng), 并設(shè)置 folder到/Users/george/Library/Mobile Documents/com~apple~CloudDocs/Personal_Sync_in_iCloud/PrefConf/profiles/iterm2_custom_folder
每個(gè)人的配置文件路徑都是不一樣的,請(qǐng)按照實(shí)際情況來設(shè)置文件夾。

- 選擇
Profiles選項(xiàng)卡,點(diǎn)擊默認(rèn)的配置項(xiàng),找到Text配置項(xiàng),配置字體為11pt Menlo Regular for Powerline
4D7BA4CE-8A0F-4B30-9259-124E62F5FDAC.png
-
重啟iTerm2,這樣我的配置文件就回來了,因?yàn)槲覀冊(cè)O(shè)置的是iCloud Drive文件夾作為配置文件夾,我們的所有改動(dòng)都會(huì)被保存到云端,而且也能共享給其他使用iCloud作為配置文件路徑的iTerm2
33A84351-5637-41A8-BE76-23E99BC4D9AC.png
更多關(guān)于iTerm2的配置
https://gist.github.com/kevin-smets/8568070
問題排查
Open iTerm2, so a default com.googlecode.iterm2.plist file is created.
Quit iTerm2
Deleted all cached preferences for iterm2 by issuing defaults delete com.googlecode.iterm2
Copied the file to the new Mac in the correct location inside Preferences folder, so I had my old profiles and settings back
Read in the prefs file with defaults read -app iTerm
Open iTerm2 and was happy to have profiles and window arrangements on my new Mac
https://apple.stackexchange.com/questions/111534/iterm2-doesnt-read-com-googlecode-iterm2-plist
https://iterm2.com/documentation-dynamic-profiles.html
Set a powerline patched font as default.
https://github.com/powerline/fonts/blob/master/Meslo%20Slashed/Meslo%20LG%20M%20Regular%20for%20Powerline.ttf
Meslo (the one in the screenshot). Click "view raw" to download the font.
使用iCloud Drive的.profile和.oh-my-zsh
我已經(jīng)有.profile和.oh-my-zsh在我的iCloud Drive中,所以我只需要關(guān)聯(lián)這些配置文件即可
export XW_HOME_FULL_PATH="/Users/`whoami`"
echo "source $XW_HOME_FULL_PATH/Library/Mobile\ Documents/com\~apple\~CloudDocs/Personal_Sync_in_iCloud/PrefConf/profiles/.profile" > ~/.profile
echo "source $XW_HOME_FULL_PATH/Library/Mobile\ Documents/com\~apple\~CloudDocs/Personal_Sync_in_iCloud/PrefConf/profiles/.zshrc" > ~/.zshrc
再次重啟iTerm2,我們的iTerm2環(huán)境就已經(jīng)配置好了

配置Dash sync
General -> Set Up Syncing
Snippets -> Open
# For syncing
/Users/georgehe/Library/Mobile Documents/com~apple~CloudDocs/Personal_Sync_in_iCloud/PrefConf/Dash/
# For snippets
/Users/georgehe/Library/Mobile Documents/com~apple~CloudDocs/Personal_Sync_in_iCloud/PrefConf/Dash/snippets.dash

配置Alfred
- 恢復(fù)license信息(沒有買PowerPack請(qǐng)略過)
- Set preferences folder到iCloud Drive
問題
- PATH里面不要不要有~,換成具體的path,path,使用
export XW_HOME_FULL_PATH=“/Users/$(whoami) - 如果HomeBrew安裝失敗或者速度過慢,可以考慮使用代理來加速
export all_proxy=<proxy_url:proxy_port>
云平臺(tái)開發(fā)運(yùn)維解決方案@george.sre
個(gè)人主頁:https://geekgoogle.com
GitHub: https://github.com/george-sre
歡迎交流~


