Created
February 9, 2017 22:45
-
-
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
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 | |
| 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