Created
October 2, 2009 00:58
-
-
Save mikew/199358 to your computer and use it in GitHub Desktop.
Helper script to open rails projects
This file contains hidden or 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
# ... | |
workon () { | |
OLDIFS=$IFS | |
IFS=$'\n' | |
output=$(workon.rb $1) | |
for line in $output; do | |
echo $line | |
done | |
eval $line | |
IFS=$OLDIFS | |
} |
This file contains hidden or 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
#!/usr/bin/env ruby | |
# Set to the root of your work directories | |
WORK_DIR = "/Users/mike/Work" | |
# Array of relevant sub directories ("languages") | |
WORK_DIRS = %w(build html php rails) | |
Dir.chdir WORK_DIR | |
@potentials = [] | |
WORK_DIRS.each do |language| | |
Dir.foreach(language) do |dir| | |
path = File.join WORK_DIR, language, dir | |
if dir == ARGV[0] | |
next if ARGV[1] && ARGV[1] != language | |
@potentials << { :language => language, :path => path } | |
end | |
end | |
end | |
def run(command, *arguments) | |
callback = arguments.last.is_a?(Proc) ? arguments.pop : lambda {} | |
puts "Running #{command}" | |
Kernel.system "#{command}", *arguments | |
callback.call | |
end | |
def commit(to) | |
destination = to[:path] | |
host = "#{ARGV[0]}.local" | |
puts "# Using #{to[:path]}" | |
run "open #{destination}" | |
run "mate #{destination}" | |
puts | |
puts "# Ping to #{host}" | |
run "ping -c 1 #{host} &> /dev/null", lambda { run "open http://#{host}" if $? == 0 } | |
puts | |
puts "# Next Step ..." | |
puts "cd #{destination}" | |
end | |
def determine_language | |
range = [email protected] | |
case @potentials.length | |
when range | |
puts "Which language did you mean?" | |
@potentials.each_index do |i| | |
key = i == 0 ? "#{i.next}*:" : "#{i.next}:" | |
puts " #{key} #{@potentials[i][:language]}" | |
end | |
index = $stdin.gets.to_i | |
commit @potentials[index == 0 ? 0 : index - 1] | |
when 1 | |
commit @potentials.first | |
else | |
puts "you fool!" | |
end | |
end | |
determine_language |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment