Skip to content

Instantly share code, notes, and snippets.

@christopherhein
Created February 9, 2017 22:45
Show Gist options
  • Save christopherhein/af8c6dd0add17546e2562297527f6dce to your computer and use it in GitHub Desktop.
Save christopherhein/af8c6dd0add17546e2562297527f6dce to your computer and use it in GitHub Desktop.
Allows you to setup very basic shortcuts to urls from the command line
#!/usr/bin/env ruby
require 'yaml'
action = ARGV[0].to_s.strip
service = ARGV[1].to_s.strip
url = ARGV[2].to_s.strip
config_file = "#{ENV['HOME']}/.shortcuts.yml"
data = File.exists?(config_file) ? YAML.load_file(config_file) : {}
case action
when 'save' then
data[service] = url
File.open(config_file, "w") { |file| file.write data.to_yaml }
when 'open' then
`open #{data[service]}`
else
if data[action]
`open #{data[action]}`
else
puts "There is no shortcut for that, try saving one first using $ shortcut save #{action} [URL]"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment