Class: CopyWish
- Inherits:
-
Djinni::Wish
- Object
- Djinni::Wish
- CopyWish
- Defined in:
- lib/rubeepass/wish/copy_wish.rb
Instance Method Summary collapse
- #aliases ⇒ Object
- #description ⇒ Object
- #execute(args, djinni_env = Hash.new) ⇒ Object
-
#initialize ⇒ CopyWish
constructor
A new instance of CopyWish.
- #tab_complete(input, djinni_env = Hash.new) ⇒ Object
- #usage ⇒ Object
Constructor Details
#initialize ⇒ CopyWish
Returns a new instance of CopyWish.
62 63 64 65 66 67 68 |
# File 'lib/rubeepass/wish/copy_wish.rb', line 62 def initialize @fields = { "pass" => "Password", "url" => "URL", "user" => "Username" } end |
Instance Method Details
#aliases ⇒ Object
4 5 6 |
# File 'lib/rubeepass/wish/copy_wish.rb', line 4 def aliases return ["copy", "cp"] end |
#description ⇒ Object
8 9 10 |
# File 'lib/rubeepass/wish/copy_wish.rb', line 8 def description return "Copy specified field to the clipboard" end |
#execute(args, djinni_env = Hash.new) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/rubeepass/wish/copy_wish.rb', line 12 def execute(args, djinni_env = Hash.new) # "".split(" ", 2) => [] aka [nil, nil] # " ".split(" ", 2) => [""] aka ["", nil] # "pass".split(" ", 2) => ["pass"] aka ["pass", nil] # "pass ".split(" ", 2) => ["pass", ""] field, path = args.split(" ", 2) if ( field.nil? || field.empty? || !@fields.include?(field) || path.nil? || path.empty? ) usage return end keepass = djinni_env["keepass"] cwd = djinni_env["cwd"] path = keepass.absolute_path(path, cwd.path) path, found, target = path.rpartition("/") new_cwd = keepass.find_group(path) timeout = djinni_env["clipboard_timeout"] if (new_cwd.nil? || !new_cwd.has_entry?(target)) puts "Entry not found" return end case field when "pass" new_cwd.entries[target].copy_password_to_clipboard keepass.send( "clear_clipboard_after_#{timeout}_seconds" ) when "url" new_cwd.entries[target].copy_url_to_clipboard keepass.send( "clear_clipboard_after_#{timeout}_seconds" ) when "user" new_cwd.entries[target].copy_username_to_clipboard keepass.send( "clear_clipboard_after_#{timeout}_seconds" ) end end |
#tab_complete(input, djinni_env = Hash.new) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/rubeepass/wish/copy_wish.rb', line 70 def tab_complete(input, djinni_env = Hash.new) # "".split(" ", 2) => [] aka [nil, nil] # " ".split(" ", 2) => [""] aka ["", nil] # "pass".split(" ", 2) => ["pass"] aka ["pass", nil] # "pass ".split(" ", 2) => ["pass", ""] field, path = input.split(" ", 2) return [@fields, "", ""] if (field.nil? || field.empty?) if (path.nil?) completions = @fields.select do |f, d| f.start_with?(field) end return [completions, field, " "] end cwd = djinni_env["cwd"] groups, entries = cwd.fuzzy_find(path) completions = Hash.new groups.each do |group| completions[group] = "Group" end entries.each do |entry| completions[entry] = "Entry" end append = "/" append = "" if (groups.empty?) return [completions, path.rpartition("/")[-1], append] end |
#usage ⇒ Object
103 104 105 106 107 108 109 110 111 |
# File 'lib/rubeepass/wish/copy_wish.rb', line 103 def usage puts "#{aliases.join(", ")} <field> <entry>" puts " #{description}." puts puts "FIELDS" @fields.each do |field, desc| puts " #{field}" end end |