Created
June 15, 2009 16:06
-
-
Save paulca/130187 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Settings -- | |
set projects_root to "~/Sites" -- where you keep your projects | |
set presets to {"project/projectname"} -- sub directories to “project_root'” | |
set visor_enabled to false -- if you use Visor “http://docs.blacktree.com/visor/visor”, set this to true | |
set rails_server_command to "tail -f log/development.log" -- My `ss` bash function will use the next available port (http://pastie.textmate.org/221395) so I can run multiple rails projects at once. if you don't have a `ss` alias/script, just use `./script/server` for mongrel/thin etc. If you're on mod_rails, just `tail -f log/development.log` | |
-- Run it | |
global rails_dir, min_window_count, presets, projects_root, visor_enabled, rails_server_command | |
main() | |
-- Main start function | |
on main() | |
my set_minimum_window_count() | |
tell application "Terminal" | |
activate | |
set rails_dir to my ask_for_rails_project_directory() | |
if not my rails_dir_exists() then | |
display alert ¬ | |
"Project is not a valid Rails directory" message ¬ | |
"The directory doesn't seem to contain some folders a Rails project usually do. Please check your path." as warning | |
else | |
my open_rails_tabs() | |
end if | |
end tell | |
end main | |
on set_minimum_window_count() | |
if visor_enabled then | |
set min_window_count to 2 -- Visor SIMBL seems to use 2 windows for itself | |
else | |
set min_window_count to 0 | |
end if | |
end set_minimum_window_count | |
on ask_for_rails_project_directory() | |
activate | |
set project_directory to ¬ | |
{choose from list presets ¬ | |
with title ¬ | |
"Choose Ruby on Rails project" OK button name ¬ | |
"Open Project" cancel button name ¬ | |
"Other Project..." default items ¬ | |
(first item of presets) with prompt "Choose any predefined project (in \"" & projects_root & "/\")"} | |
-- If no project selected (i.e. clicked on Cancel), ask user to manually enter a project's path | |
if project_directory = {false} then | |
set project_directory to the text returned of (display dialog ¬ | |
"Please Enter the Path to Your Rails Directory" default answer ¬ | |
projects_root as text) | |
else | |
set project_directory to projects_root & "/" & project_directory | |
end if | |
return project_directory | |
end ask_for_rails_project_directory | |
on rails_dir_exists() | |
set dir_exists to false | |
try | |
do shell script "cd " & rails_dir & " && [[ -x app ]] && [[ -x config ]] && echo exists" | |
if text of result is "exists" then | |
set dir_exists to true | |
else | |
set dir_exists to false | |
end if | |
on error | |
set dir_exists to false | |
end try | |
return dir_exists as boolean | |
end rails_dir_exists | |
on open_rails_tabs() | |
tell application "Terminal" to do script | |
my open_tab("Server", rails_server_command) | |
my open_tab("Autospec", "AUTOFEATURE=true autospec") | |
my open_tab("Console", "./script/console") | |
my open_tab("Rails Directory", "clear") -- I use `mater` from http://pastie.textmate.org/221354 instead of `mate .` | |
my open_tab("MySQL", "m") | |
my open_tab("Remote", "clear") | |
end open_rails_tabs | |
on open_tab(title, the_command) | |
tell application "Terminal" to activate | |
my create_new_window_or_tabs() | |
tell application "Terminal" to ¬ | |
do script with command ("cd " & rails_dir & "&& unset PROMPT_COMMAND && echo -n -e \"\\e]0;" & title & "\\a\" && " & the_command) ¬ | |
in last tab of window 1 | |
end open_tab | |
on create_new_window_or_tabs() | |
if (count of windows of application "Terminal") ≤ min_window_count then | |
tell application "Terminal" to do script "" -- create a new window | |
else | |
tell application "System Events" to tell process "Terminal" to keystroke "t" using command down | |
end if | |
end create_new_window_or_tabs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment