| 
									
										
										
										
											2014-10-10 04:00:19 -07:00
										 |  |  | import os | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | from invoke import ctask | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-21 11:00:04 -07:00
										 |  |  | from . import util | 
					
						
							| 
									
										
										
										
											2014-10-10 04:00:19 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @ctask(default=True) | 
					
						
							| 
									
										
										
										
											2014-11-11 15:52:25 -08:00
										 |  |  | def setup(ctx): | 
					
						
							|  |  |  |     brew(ctx) | 
					
						
							|  |  |  |     cider(ctx) | 
					
						
							|  |  |  |     access_for_assistive_devices(ctx) | 
					
						
							|  |  |  |     hyper(ctx) | 
					
						
							|  |  |  |     locate(ctx) | 
					
						
							|  |  |  |     set_path_for_launchd(ctx) | 
					
						
							| 
									
										
										
										
											2015-01-02 15:09:48 -08:00
										 |  |  |     rvm(ctx) | 
					
						
							|  |  |  |     fonts(ctx) | 
					
						
							| 
									
										
										
										
											2014-12-21 04:05:07 -08:00
										 |  |  |     fix_htop(ctx) | 
					
						
							| 
									
										
										
										
											2015-01-21 18:42:18 -08:00
										 |  |  |     iTerm(ctx) | 
					
						
							| 
									
										
										
										
											2015-01-21 16:58:29 -08:00
										 |  |  |     # setup_dbus(ctx) | 
					
						
							| 
									
										
										
										
											2015-01-21 18:42:18 -08:00
										 |  |  |     keyboard_settings(ctx) | 
					
						
							|  |  |  |     clear_dock(ctx) | 
					
						
							| 
									
										
										
										
											2014-10-10 04:00:19 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-21 04:05:07 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-19 15:40:02 -08:00
										 |  |  | @ctask | 
					
						
							|  |  |  | def macvim(ctx): | 
					
						
							|  |  |  |     macvim_install = ( | 
					
						
							|  |  |  |         "macvim --override-system-vim --custom-system-icons " | 
					
						
							|  |  |  |         "--with-features=huge --enable-rubyinterp --enable-pythoninterp " | 
					
						
							|  |  |  |         "--enable-perlinterp --enable-cscope" | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     ctx.run("brew install {0}".format(macvim_install)) | 
					
						
							|  |  |  |     ctx.run("vim +BundleInstall! +q +q") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-10 08:18:28 -08:00
										 |  |  | @ctask | 
					
						
							|  |  |  | def setup_dbus(ctx): | 
					
						
							|  |  |  |     ctx.run("ln -sfv /usr/local/opt/d-bus/*.plist ~/Library/LaunchAgents") | 
					
						
							| 
									
										
										
										
											2014-10-10 04:00:19 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | @ctask | 
					
						
							|  |  |  | def osx_config(ctx): | 
					
						
							| 
									
										
										
										
											2014-10-23 15:42:28 -07:00
										 |  |  |     ctx.run('sudo {0}'.format( | 
					
						
							| 
									
										
										
										
											2014-10-21 11:00:04 -07:00
										 |  |  |         os.path.join(util.RESOURCES_DIRECTORY, 'osx.sh') | 
					
						
							| 
									
										
										
										
											2014-10-23 15:42:28 -07:00
										 |  |  |     ), pty=True) | 
					
						
							| 
									
										
										
										
											2014-10-21 11:00:04 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-10 00:13:30 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-31 17:07:28 -07:00
										 |  |  | @ctask | 
					
						
							| 
									
										
										
										
											2014-11-11 15:52:25 -08:00
										 |  |  | def cider(ctx): | 
					
						
							| 
									
										
										
										
											2014-11-10 00:13:30 -08:00
										 |  |  |     ctx.run('brew install caskroom/cask/brew-cask') | 
					
						
							| 
									
										
										
										
											2014-10-31 18:34:49 -07:00
										 |  |  |     if not util.command_exists('cider'): | 
					
						
							|  |  |  |         ctx.run('sudo pip install cider') | 
					
						
							| 
									
										
										
										
											2014-12-18 09:31:22 -08:00
										 |  |  |     ctx.run('cider restore -i') | 
					
						
							| 
									
										
										
										
											2014-10-31 17:07:28 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-10 04:00:19 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | @ctask | 
					
						
							| 
									
										
										
										
											2014-11-11 15:52:25 -08:00
										 |  |  | def brew(ctx): | 
					
						
							|  |  |  |     path = 'https://raw.githubusercontent.com/Homebrew/install/master/install)' | 
					
						
							| 
									
										
										
										
											2014-10-21 11:00:04 -07:00
										 |  |  |     if not util.command_exists('brew'): | 
					
						
							| 
									
										
										
										
											2014-11-11 15:52:25 -08:00
										 |  |  |         ctx.run('ruby -e "$(curl -fsSL {0}'.format(path)) | 
					
						
							| 
									
										
										
										
											2014-10-10 04:00:19 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-10 00:13:30 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-10 04:00:19 -07:00
										 |  |  | @ctask | 
					
						
							| 
									
										
										
										
											2014-11-11 15:52:25 -08:00
										 |  |  | def packages(ctx): | 
					
						
							| 
									
										
										
										
											2014-10-28 14:09:59 -07:00
										 |  |  |     ctx.run('brew update') | 
					
						
							| 
									
										
										
										
											2014-10-10 04:00:19 -07:00
										 |  |  |     for package_name in ESSENTIAL + BASICS + SHOULD_INSTALL + MISC: | 
					
						
							|  |  |  |         ctx.run('brew install {0}'.format(package_name)) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-21 11:00:04 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-20 20:15:11 -07:00
										 |  |  | @ctask | 
					
						
							| 
									
										
										
										
											2014-11-11 15:52:25 -08:00
										 |  |  | def set_path_for_launchd(ctx): | 
					
						
							| 
									
										
										
										
											2014-10-21 11:00:04 -07:00
										 |  |  |     launch_agent_dir = os.path.expanduser('~/Library/LaunchAgents/') | 
					
						
							|  |  |  |     filename = 'set-path.plist' | 
					
						
							| 
									
										
										
										
											2014-10-21 15:20:43 -07:00
										 |  |  |     source = os.path.join(util.RESOURCES_DIRECTORY, filename) | 
					
						
							|  |  |  |     destination = os.path.join(launch_agent_dir, filename) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if os.path.exists(source) and not os.path.exists(destination): | 
					
						
							|  |  |  |         util.ensure_path_exists(launch_agent_dir) | 
					
						
							|  |  |  |         ctx.run('ln -s {0} {1}'.format(source, destination)) | 
					
						
							| 
									
										
										
										
											2014-10-20 20:15:11 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-23 02:38:27 -07:00
										 |  |  | APPS_NEEDING_ASSISTIVE_DEVICE_ACCESS = ('Slate', 'Synergy', 'iTerm') | 
					
						
							|  |  |  | @ctask | 
					
						
							| 
									
										
										
										
											2014-11-11 15:52:25 -08:00
										 |  |  | def access_for_assistive_devices(ctx): | 
					
						
							| 
									
										
										
										
											2014-10-23 02:38:27 -07:00
										 |  |  |     for app in APPS_NEEDING_ASSISTIVE_DEVICE_ACCESS: | 
					
						
							|  |  |  |         app_string = '/Applications/{0}.app'.format(app) | 
					
						
							|  |  |  |         user_application = os.path.expanduser('~' + app_string) | 
					
						
							| 
									
										
										
										
											2014-11-11 15:52:25 -08:00
										 |  |  |         access_if_exists(ctx, user_application) | 
					
						
							|  |  |  |         access_if_exists(ctx, app_string) | 
					
						
							|  |  |  |         access_if_exists( | 
					
						
							| 
									
										
										
										
											2014-10-25 17:51:05 -07:00
										 |  |  |             ctx, | 
					
						
							| 
									
										
										
										
											2014-11-11 15:52:25 -08:00
										 |  |  |             "/Applications/Karabiner.app/Contents/Applications/" | 
					
						
							|  |  |  |             "Karabiner_AXNotifier.app" | 
					
						
							| 
									
										
										
										
											2014-10-25 17:51:05 -07:00
										 |  |  |         ) | 
					
						
							| 
									
										
										
										
											2014-10-24 06:19:23 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-11 15:52:25 -08:00
										 |  |  | def access_if_exists(ctx, app_string): | 
					
						
							| 
									
										
										
										
											2014-10-24 06:19:23 -07:00
										 |  |  |     if os.path.exists(app_string): | 
					
						
							|  |  |  |         ctx.run( | 
					
						
							|  |  |  |             'zsh -c "source ~/.zshrc && ' | 
					
						
							|  |  |  |             'enable_access_for_assistive_devices \"{0}\""'.format( | 
					
						
							|  |  |  |                 app_string | 
					
						
							| 
									
										
										
										
											2014-10-23 02:38:27 -07:00
										 |  |  |             ) | 
					
						
							| 
									
										
										
										
											2014-10-24 06:19:23 -07:00
										 |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-02 15:09:48 -08:00
										 |  |  | @ctask(aliases=['karabiner', 'fast_repeat']) | 
					
						
							| 
									
										
										
										
											2014-11-11 15:52:25 -08:00
										 |  |  | def hyper(ctx): | 
					
						
							| 
									
										
										
										
											2014-10-24 06:19:23 -07:00
										 |  |  |     source = '{0}/karabiner-hyper.xml'.format(util.RESOURCES_DIRECTORY) | 
					
						
							| 
									
										
										
										
											2014-12-31 11:13:40 -05:00
										 |  |  |     destination_folder = os.path.join( | 
					
						
							|  |  |  |         os.path.expanduser("~/Library"), "Application\\ Support", "Karabiner" | 
					
						
							| 
									
										
										
										
											2014-11-11 15:52:25 -08:00
										 |  |  |     ) | 
					
						
							| 
									
										
										
										
											2014-12-31 11:13:40 -05:00
										 |  |  |     destination = os.path.join(destination_folder, "private.xml") | 
					
						
							| 
									
										
										
										
											2014-10-24 06:19:23 -07:00
										 |  |  |     try: | 
					
						
							|  |  |  |         ctx.run("rm {0}".format(destination)) | 
					
						
							|  |  |  |     except: | 
					
						
							|  |  |  |         pass | 
					
						
							| 
									
										
										
										
											2014-12-31 11:13:40 -05:00
										 |  |  |     util.ensure_path_exists(destination_folder) | 
					
						
							| 
									
										
										
										
											2014-10-24 06:19:23 -07:00
										 |  |  |     ctx.run("ln -s {0} {1}".format(source, destination)) | 
					
						
							|  |  |  |     ctx.run("{0}/karabiner_config.sh".format(util.RESOURCES_DIRECTORY)) | 
					
						
							| 
									
										
										
										
											2014-10-23 02:38:27 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-10 02:00:46 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-10 04:00:19 -07:00
										 |  |  | @ctask | 
					
						
							| 
									
										
										
										
											2014-11-11 15:52:25 -08:00
										 |  |  | def locate(ctx): | 
					
						
							|  |  |  |     ctx.run('sudo launchctl load -w ' | 
					
						
							|  |  |  |             '/System/Library/LaunchDaemons/com.apple.locate.plist') | 
					
						
							| 
									
										
										
										
											2014-11-10 02:00:46 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-28 14:09:59 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-09 22:18:16 -08:00
										 |  |  | @ctask | 
					
						
							| 
									
										
										
										
											2015-01-02 15:09:48 -08:00
										 |  |  | def rvm(ctx): | 
					
						
							| 
									
										
										
										
											2014-11-11 15:52:25 -08:00
										 |  |  |     ctx.run('\\curl -sSL https://get.rvm.io | bash -s stable') | 
					
						
							| 
									
										
										
										
											2014-11-09 22:18:16 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-10 02:00:46 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-28 14:09:59 -07:00
										 |  |  | @ctask | 
					
						
							| 
									
										
										
										
											2015-01-02 15:09:48 -08:00
										 |  |  | def fonts(ctx): | 
					
						
							| 
									
										
										
										
											2014-11-11 15:52:25 -08:00
										 |  |  |     ctx.run('open {0}'.format( | 
					
						
							|  |  |  |         os.path.join(util.RESOURCES_DIRECTORY, "Monaco-Powerline.otf")) | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2014-11-10 02:00:46 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @ctask | 
					
						
							| 
									
										
										
										
											2014-11-11 15:52:25 -08:00
										 |  |  | def cl_tools(ctx): | 
					
						
							| 
									
										
										
										
											2014-11-10 02:00:46 -08:00
										 |  |  |     if not util.command_exists('gcc'): | 
					
						
							|  |  |  |         ctx.run('xcode-select --install') | 
					
						
							| 
									
										
										
										
											2014-11-13 20:40:06 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-20 01:23:42 -08:00
										 |  |  | @ctask | 
					
						
							|  |  |  | def fix_htop(ctx): | 
					
						
							|  |  |  |     real_htop_location = ctx.run("readlink -f $(brew --prefix htop)").stdout.strip() + "/bin/htop" | 
					
						
							| 
									
										
										
										
											2014-12-31 11:13:27 -05:00
										 |  |  |     ctx.run("sudo chmod 6555 {0}".format(real_htop_location)) | 
					
						
							| 
									
										
										
										
											2014-12-20 01:23:42 -08:00
										 |  |  |     ctx.run("sudo chown root {0}".format(real_htop_location)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-13 20:40:06 -08:00
										 |  |  | @ctask | 
					
						
							|  |  |  | def iTerm(ctx): | 
					
						
							|  |  |  |     library_plist = os.path.join(os.path.expanduser("~"), "Library", | 
					
						
							|  |  |  |                                  "Preferences", "com.googlecode.iterm2.plist") | 
					
						
							|  |  |  |     ctx.run("defaults write {0} LoadPrefsFromCustomFolder -bool true".format( | 
					
						
							|  |  |  |         library_plist | 
					
						
							|  |  |  |     )) | 
					
						
							|  |  |  |     ctx.run("defaults write {0} PrefsCustomFolder -string {1}".format( | 
					
						
							|  |  |  |         library_plist, util.RESOURCES_DIRECTORY | 
					
						
							|  |  |  |     )) | 
					
						
							| 
									
										
										
										
											2014-12-21 04:05:07 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-22 13:08:12 -05:00
										 |  |  | @ctask | 
					
						
							|  |  |  | def launch_agents(ctx, flags=''): | 
					
						
							|  |  |  |     ctx.run('dotfiles -sn{1} -R {0}/resources/LaunchAgents/ ' | 
					
						
							|  |  |  |             '-H ~/Library/LaunchAgents'.format(util.REPO_DIRECTORY, flags)) | 
					
						
							| 
									
										
										
										
											2015-01-21 16:58:29 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @ctask | 
					
						
							|  |  |  | def keyboard_settings(ctx): | 
					
						
							| 
									
										
										
										
											2015-01-21 17:02:00 -08:00
										 |  |  |     ctx.run("zsh -c 'refresh_config && set_modifier_keys_on_all_keyboards'") | 
					
						
							| 
									
										
										
										
											2015-01-21 18:42:18 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @ctask | 
					
						
							|  |  |  | def configure_dock(ctx): | 
					
						
							|  |  |  |    ctx.run("zsh -c 'refresh_config && clear_dock'") | 
					
						
							| 
									
										
										
										
											2015-01-21 22:59:25 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | osx_settings_directory = os.path.join(util.RESOURCES_DIRECTORY, 'osx_settings') | 
					
						
							|  |  |  | all_save_osx_settings = [] | 
					
						
							|  |  |  | all_write_osx_settings = [] | 
					
						
							|  |  |  | all_diff_osx_settings = [] | 
					
						
							|  |  |  | def functions_for_filename(filename): | 
					
						
							|  |  |  |     filepath = os.path.join(osx_settings_directory, filename) | 
					
						
							|  |  |  |     task_name = 'osx_settings-write:' + filename.replace('.', '-') | 
					
						
							|  |  |  |     @ctask(name=task_name) | 
					
						
							|  |  |  |     def task(ctx): | 
					
						
							|  |  |  |         ctx.run("defaults write {0} '$(cat {1})'".format( | 
					
						
							|  |  |  |             filename, filepath | 
					
						
							|  |  |  |         )) | 
					
						
							|  |  |  |     globals()[task_name] = task | 
					
						
							|  |  |  |     all_write_osx_settings.append(task) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     task_name = 'osx_settings-save:' + filename.replace('.', '-') | 
					
						
							|  |  |  |     @ctask(name=task_name) | 
					
						
							|  |  |  |     def task(ctx): | 
					
						
							|  |  |  |         ctx.run("defaults read {0} > {1}".format( | 
					
						
							|  |  |  |             filename, filepath | 
					
						
							|  |  |  |         )) | 
					
						
							|  |  |  |     globals()[task_name] = task | 
					
						
							|  |  |  |     all_save_osx_settings.append(task) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     task_name = 'osx_settings-diff:' + filename.replace('.', '-') | 
					
						
							|  |  |  |     @ctask(name=task_name) | 
					
						
							|  |  |  |     def task(ctx): | 
					
						
							|  |  |  |         print filepath | 
					
						
							|  |  |  |         print filename | 
					
						
							|  |  |  |         ctx.run("zsh -c 'icdiff <(defaults read {0}) {1}'".format( | 
					
						
							|  |  |  |             filename, filepath | 
					
						
							|  |  |  |         )) | 
					
						
							|  |  |  |     globals()[task_name] = task | 
					
						
							|  |  |  |     all_diff_osx_settings.append(task) | 
					
						
							|  |  |  | for _, _, filenames in os.walk(osx_settings_directory): | 
					
						
							|  |  |  |     for filename in filenames: | 
					
						
							|  |  |  |         functions_for_filename(filename) |