Class: ShowWish
- Inherits:
-
Djinni::Wish
- Object
- Djinni::Wish
- ShowWish
- Defined in:
- lib/rubeepass/wish/show_wish.rb
Instance Method Summary collapse
- #aliases ⇒ Object
- #description ⇒ Object
- #execute(args, djinni_env = {}) ⇒ Object
- #tab_complete(input, djinni_env = {}) ⇒ Object
- #usage ⇒ Object
Instance Method Details
#aliases ⇒ Object
5 6 7 |
# File 'lib/rubeepass/wish/show_wish.rb', line 5 def aliases return [ "cat", "show" ] end |
#description ⇒ Object
9 10 11 |
# File 'lib/rubeepass/wish/show_wish.rb', line 9 def description return "Show group/entry contents" 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 |
# File 'lib/rubeepass/wish/show_wish.rb', line 13 def execute(args, djinni_env = {}) 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?) puts new_cwd elsif (new_cwd.has_group?(target)) puts new_cwd.groups[target] elsif (new_cwd.has_entry?(target)) new_cwd.entry_titles.select do |entry| target.downcase == entry.downcase end.each do |entry| puts new_cwd.entries[entry] end else puts "Group/entry \"#{args}\" doesn't exist!" end else puts "Group/entry \"#{args}\" doesn't exist!" end end |
#tab_complete(input, djinni_env = {}) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/rubeepass/wish/show_wish.rb', line 41 def tab_complete(input, djinni_env = {}) cwd = djinni_env["cwd"] input, groups, entries = cwd.fuzzy_find(input) if (groups.empty? && entries.empty?) return input.gsub(%r{^#{cwd.path}/?}, "") end path, target = input.rsplit("/") if (target.empty?) if ((groups.length == 1) && entries.empty?) input = "#{path}/#{groups.first}/" return input.gsub(%r{^#{cwd.path}/?}, "") elsif (groups.empty? && (entries.length == 1)) input = "#{path}/#{entries.first}" return input.gsub(%r{^#{cwd.path}/?}, "") end puts groups.each do |group| puts "#{group}/" end puts entries return input.gsub(%r{^#{cwd.path}/?}, "") end if (!groups.empty?) input = "#{path}/#{groups.first}/" elsif (!entries.empty?) input = "#{path}/#{entries.first}" end return input.gsub(%r{^#{cwd.path}/?}, "") end |
#usage ⇒ Object
75 76 77 78 |
# File 'lib/rubeepass/wish/show_wish.rb', line 75 def usage puts "#{aliases.join(", ")} [group|entry]" puts "\t#{description}." end |