使用iCloud共享的配置文件快速配置新Mac电脑

使用iCloud共享的配置文件快速配置新Mac电脑

本文我们介绍如何利用iCloud共享的配置文件来快速配置一台新的Mac电脑,以此实现多台电脑分享同一套配置的目的。

Screen Shot 2019-05-19 at 12.53.27 AM.png

准备工作

  • 需要Apple iCloud的支持
  • iCloud Drive中已经存有以下软件的配置文件或目录

工具列表

设置iCloud

环境相关的配置文件我基本上都放在iCloud Drive中,使用iCloud的同步功能,配置文件可以保存在云端,也可以共享给多个Mac电脑使用。
登陆iCloud,并关闭iCloud Drive的 Optimise Mac Storage功能。然后我们等待所有的iCloud文件同步到新Mac上。

52DECAA0-1988-4179-9435-63B5C881B712.png

软件的安装

  1. 安装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)
  1. 使用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

  1. 第一次打开Iterm2,软件会提示需要给Full Disk Access权限,请前往”Security & Privacy”中心进行授权。
    iterm2.gif
  1. 从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

每个人的配置文件路径都是不一样的,请按照实际情况来设置文件夹。

BF4ADD9E-5D87-48A3-B7E2-6E337120FC0F.png
  1. 选择Profiles选项卡,点击默认的配置项,找到Text配置项,配置字体为11pt Menlo Regular for Powerline
    4D7BA4CE-8A0F-4B30-9259-124E62F5FDAC.png
  1. 重启iTerm2,这样我的配置文件就回来了,因为我们设置的是iCloud Drive文件夹作为配置文件夹,我们的所有改动都会被保存到云端,而且也能共享给其他使用iCloud作为配置文件路径的iTerm2


    33A84351-5637-41A8-BE76-23E99BC4D9AC.png

更多关于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环境就已经配置好了


263598F0-4621-45E3-8E88-BB1760114AAA.png

配置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
41BF9C7A-97EE-4E81-BEFF-FBD0DD2142FF.png

配置Alfred

  1. 恢复license信息(没有买PowerPack请略过)
  2. 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

个人主页:https://geekgoogle.com

GitHub: https://github.com/george-sre

Mail: george.sre@hotmail.com

简书: georgesre - 简书

欢迎交流~

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容