#!/usr/bin/env ruby require 'rubygems' require 'pp' require 'appscript' require 'mixlib/cli' class MacDevStart include Mixlib::CLI include Appscript SERVICES = %w{couchdb rabbitmq chef_solr chef_expander chef_server chef_webui} option :environment, :short => '-e ENV', :long => '--environment ENV', :default => 'test', :description => 'Set the environment (test|dev), defaults to test' def run @srcdir = File.expand_path(File.dirname(__FILE__)) @base_cmd = case config[:environment] when 'test' "cd #{@srcdir} && rake dev:features:start:" when 'dev' "cd #{@srcdir} && rake dev:start:" else puts "--environment must be set to either 'test' or 'dev'" puts @opt_parser exit 1 end STDOUT.puts "Starting services:" pp SERVICES start_services(SERVICES) end def create_tab @window.activate app("System Events").application_processes["Terminal.app"].keystroke("t", :using=>:command_down) end def terminal_app @terminal_app ||= app("Terminal") end def create_term_window terminal_app.windows.first.activate app("System Events").application_processes["Terminal.app"].keystroke("n", :using=>:command_down) @window = terminal_app.windows.first.get end def start_service_in_tab(service, tab) # use xterm escape codes to set the tab title to the service running in the tab. cmd = "unset PROMPT_COMMAND; echo -e \"\\033]0;#{service}\\007\"; #{@base_cmd}#{service}" app('Terminal').do_script(cmd, :in => @window.tabs[tab].get) end def start_services(services) create_term_window tab_index = 1 # applescript indexes from 1 instead of 0 (services.size - 1).times { create_tab } services.each do |service| start_service_in_tab(service, tab_index) tab_index += 1 end end end if __FILE__ == $0 os = MacDevStart.new os.parse_options os.run end