使用iCloud共享的配置文件快速配置新Mac电脑
本文我们介绍如何利用iCloud共享的配置文件来快速配置一台新的Mac电脑,以此实现多台电脑分享同一套配置的目的。
准备工作
- 需要Apple iCloud的支持
- iCloud Drive中已经存有以下软件的配置文件或目录
工具列表
设置iCloud
环境相关的配置文件我基本上都放在iCloud Drive中,使用iCloud的同步功能,配置文件可以保存在云端,也可以共享给多个Mac电脑使用。
登陆iCloud,并关闭iCloud Drive的 Optimise Mac Storage
功能。然后我们等待所有的iCloud文件同步到新Mac上。
软件的安装
- 安装Homebrew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
安装成功的验证命令:
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安装基本的环境(brew安装软件可任选,我把我的所有HomeBrew软件都罗列于此)
因为有些软件需要手工输入当前账户的密码,建议一个个软件安装下去
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,软件会提示需要给
Full Disk Access
权限,请前往”Security & Privacy”中心进行授权。
- 从iCloud Drive中恢复(设置)默认配置文件
再次打开iTerm2,打开preferences定位到General. 找到页面最底部的 “Load preferences from a custom folder or URL”. 选择此选项, 并设置 folder到/Users/george/Library/Mobile Documents/com~apple~CloudDocs/Personal_Sync_in_iCloud/PrefConf/profiles/iterm2_custom_folder
每个人的配置文件路径都是不一样的,请按照实际情况来设置文件夹。
- 选择
Profiles
选项卡,点击默认的配置项,找到Text
配置项,配置字体为11pt Menlo Regular for Powerline
-
重启iTerm2,这样我的配置文件就回来了,因为我们设置的是iCloud Drive文件夹作为配置文件夹,我们的所有改动都会被保存到云端,而且也能共享给其他使用iCloud作为配置文件路径的iTerm2
更多关于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
我已经有.profile
和.oh-my-zsh
在我的iCloud Drive中,所以我只需要关联这些配置文件即可
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环境就已经配置好了
配置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
- 恢复license信息(没有买PowerPack请略过)
- Set preferences folder到iCloud Drive
问题
- PATH里面不要不要有~,换成具体的path,path,使用
export XW_HOME_FULL_PATH=“/Users/$(whoami)
- 如果HomeBrew安装失败或者速度过慢,可以考虑使用代理来加速
export all_proxy=<proxy_url:proxy_port>
云平台开发运维解决方案@george.sre
GitHub: https://github.com/george-sre
欢迎交流~