Last active
July 30, 2018 20:12
-
-
Save mattroyer/33028bcb40f6d29bc316bd1e72873672 to your computer and use it in GitHub Desktop.
Drop(p) named URLs or paths into a JSON file so you can easily retrieve them later
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
require 'json' | |
action, name, path = ARGV | |
filename = ".dropp" | |
$config = File.exist?("#{ENV['USERPROFILE']}/#{filename}") ? JSON.parse(File.read("#{ENV['USERPROFILE']}/#{filename}")) : {} | |
def truncate(string, max=65) | |
string.length > max ? "#{string[0...max]}..." : string | |
end | |
def add name, path | |
$config[name] = path | |
save | |
end | |
def get name | |
$config[name] | |
end | |
def open_path name | |
`start #{$config[name]}` | |
end | |
def remove_item key | |
$config.delete key | |
save | |
end | |
def save | |
File.open("#{ENV['USERPROFILE']}/.dropp", "w") do |f| | |
f.puts $config.to_json | |
end | |
end | |
case action | |
when "add" | |
puts "Added #{name} - #{path}" | |
add name, path | |
when "get" | |
# For Windows | |
puts "Copied #{get name} to the clipboard!" | |
`echo #{get name} | clip` | |
when "open" | |
open_path name | |
when "delete" | |
remove_item name | |
when "list" | |
abort("No list found. Try adding some items with the 'add' action.") if $config == {} | |
$config.each do |key, value| | |
puts "#{key} - #{truncate(value)}" | |
end | |
else | |
usage = """\n Usage: | |
add <name> <url|path> // Add url or path by name to the db | |
get <name> // Get url or path by name | |
open <name> // Copy url or path by name to clipboard | |
delete <name> // Delete the item from the db | |
list // Lists all saved items""" | |
puts usage | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Not pretty. Quick hack. But it works.