Created
August 4, 2008 14:40
-
-
Save brennandunn/3901 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
#!/usr/bin/env ruby | |
Locations = { | |
'vatican' => 'home', | |
'dbstation' => 'remote' | |
} | |
Dotfile = ENV['RUN_AS'] ? File.expand_path("/Users/#{ENV['RUN_AS']}/.location") : File.expand_path('~/.location') | |
# ensure dotfile exists | |
File.open(Dotfile, 'w') { |f| f.write(Locations.keys.first) } unless File.exists?(Dotfile) | |
if ARGV.empty? || ARGV.first == '-s' | |
location = File.read(Dotfile) | |
if !ARGV.empty? | |
puts location | |
else | |
puts "#{Locations[location]} (host: #{location})" | |
end | |
else | |
location = Locations.detect { |h,l| l == ARGV.first } | |
if location | |
puts "Changing location to #{location.last}" | |
File.open(Dotfile ,'w') { |f| f.write(location.first) } | |
else | |
puts "Error: Can't find location #{ARGV.first}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment