Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'json'
- action, name, path = ARGV
- filename = ".dropp"
- $config = 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 save
- File.open("#{ENV['USERPROFILE']}/.dropp", "w") do |f|
- f.puts $config.to_json
- end
- end
- case action
- when "add"
- add name, path
- when "get"
- # For Windows
- `echo #{get name} | clip`
- when "open"
- open_path name
- when "list"
- $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
- list // Lists all saved items"""
- puts usage
- end
Add Comment
Please, Sign In to add comment