Class: EchoWish
- Inherits:
-
Djinni::Wish
- Object
- Djinni::Wish
- EchoWish
- Defined in:
- lib/rubeepass/wish/echo_wish.rb
Instance Method Summary collapse
- #aliases ⇒ Object
- #description ⇒ Object
- #execute(args, djinni_env = {}) ⇒ Object
-
#initialize ⇒ EchoWish
constructor
A new instance of EchoWish.
- #tab_complete(input, djinni_env = {}) ⇒ Object
- #usage ⇒ Object
Constructor Details
#initialize ⇒ EchoWish
Returns a new instance of EchoWish.
57 58 59 |
# File 'lib/rubeepass/wish/echo_wish.rb', line 57 def initialize @fields = [ "pass", "url", "user" ] end |
Instance Method Details
#aliases ⇒ Object
5 6 7 |
# File 'lib/rubeepass/wish/echo_wish.rb', line 5 def aliases return [ "echo" ] end |
#description ⇒ Object
9 10 11 |
# File 'lib/rubeepass/wish/echo_wish.rb', line 9 def description return "Echo specified field to stdout" end |
#execute(args, djinni_env = {}) ⇒ Object
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 |
# File 'lib/rubeepass/wish/echo_wish.rb', line 13 def execute(args, djinni_env = {}) if (args.nil? || args.empty?) puts usage return end field, args = args.split(" ", 2) if (!@fields.include?(field)) puts usage return end keepass = djinni_env["keepass"] cwd = djinni_env["cwd"] args = cwd.path if (args.nil? || args.empty?) args = keepass.absolute_path(args, cwd.path) path, target = args.rsplit("/") new_cwd = keepass.find_group(path) if (new_cwd) if (target.empty?) usage elsif (new_cwd.has_entry?(target)) target = new_cwd.entry_titles.select do |entry| target.downcase == entry.downcase end.first case field when "pass" new_cwd.entries[target].echo_password when "url" new_cwd.entries[target].echo_url when "user" new_cwd.entries[target].echo_username end else puts "Entry \"#{args}\" doesn't exist!" end else puts "Entry \"#{args}\" doesn't exist!" end end |
#tab_complete(input, djinni_env = {}) ⇒ Object
61 62 63 64 65 66 67 68 69 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 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/rubeepass/wish/echo_wish.rb', line 61 def tab_complete(input, djinni_env = {}) if (input.nil? || input.empty?) puts puts @fields return "" end field, input = input.split(" ", 2) if (input.nil? || input.empty?) @fields.each do |f| break if (f == field) if (f.start_with?(field)) return "#{f} " end end end input = "" if (input.nil?) cwd = djinni_env["cwd"] input, groups, entries = cwd.fuzzy_find(input) if (groups.empty? && entries.empty?) return "#{field} #{input.gsub(%r{^#{cwd.path}/?}, "")}" end path, target = input.rsplit("/") if (target.empty?) if ((groups.length == 1) && entries.empty?) input = "#{path}/#{groups.first}/" return "#{field} #{input.gsub(%r{^#{cwd.path}/?}, "")}" elsif (groups.empty? && (entries.length == 1)) input = "#{path}/#{entries.first}" return "#{field} #{input.gsub(%r{^#{cwd.path}/?}, "")}" end puts groups.each do |group| puts "#{group}/" end puts entries return "#{field} #{input.gsub(%r{^#{cwd.path}/?}, "")}" end if (!groups.empty?) input = "#{path}/#{groups.first}/" elsif (!entries.empty?) input = "#{path}/#{entries.first}" end return "#{field} #{input.gsub(%r{^#{cwd.path}/?}, "")}" end |
#usage ⇒ Object
114 115 116 117 118 119 120 121 122 |
# File 'lib/rubeepass/wish/echo_wish.rb', line 114 def usage puts "#{aliases.join(", ")} <field> <entry>" puts "\t#{description}." puts puts "FIELDS" @fields.each do |field| puts "\t#{field}" end end |