Skip to content

Instantly share code, notes, and snippets.

@brennandunn
Created August 4, 2008 14:40
Show Gist options
  • Save brennandunn/3901 to your computer and use it in GitHub Desktop.
Save brennandunn/3901 to your computer and use it in GitHub Desktop.
#!/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