rubeepass 0.2.4 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 50fa9c39b81cfba5ca3fa62523807f0332856606
4
- data.tar.gz: 3607dc60aaa4b4d074a0acc68bb2eaec4cf7a193
3
+ metadata.gz: 653ac4cb3a93bbbe7c2251b4991d53450ca6f9ae
4
+ data.tar.gz: 9b0d2766e17526fe97804bc22408ca4f8c6cfc45
5
5
  SHA512:
6
- metadata.gz: 0081a426f6ab744f2a8f54bebf825959e352637cf1e556857abcb188c53d91faadbadb968fa4386f3a69a79b1c55f07164209f18e1224a24601fc6f7090b25a7
7
- data.tar.gz: d4e0190ed211f367722b9ba77b8f0bbcb56a92e78c3f8ff029e28d522e8a8dd48ff5effb8490031dccbf00701ae00be6a04b2dd32a8e81bc4e3646307a647eff
6
+ metadata.gz: 364dad75384baa2bb01cdca559a5561beb52b2c5fc3c2a034a2160ad30344d6df13c15324513392674b9ebb5ddd064699a145cdf0f487e88d451cd4b62db14f7
7
+ data.tar.gz: cf5daf1ee477f3d57a23d54497f61cc50083b76492e6d31c5cb11d7acec38a62a47bc5603227cccba6b920beba73426f77d9651975772dd792504988600d9361
data/bin/rpass CHANGED
@@ -38,6 +38,7 @@ end
38
38
 
39
39
  def parse(args)
40
40
  options = Hash.new
41
+ options["command"] = nil
41
42
  options["export_file"] = nil
42
43
  options["export_format"] = "xml"
43
44
  options["password"] = nil
@@ -47,6 +48,14 @@ def parse(args)
47
48
  parser = OptionParser.new do |opts|
48
49
  opts.banner = "Usage: #{File.basename($0)} [OPTIONS] [kdbx]"
49
50
 
51
+ opts.on(
52
+ "-c",
53
+ "--command=COMMAND",
54
+ "Run a command then exit"
55
+ ) do |command|
56
+ options["command"] = command
57
+ end
58
+
50
59
  opts.on(
51
60
  "-e",
52
61
  "--export=FILE",
@@ -244,12 +253,24 @@ end
244
253
 
245
254
  djinni = Djinni.new
246
255
  djinni.load_wishes("#{File.dirname(__FILE__)}/../lib/builtins")
247
- djinni.prompt(
248
- {
249
- "keepass" => keepass,
250
- "cwd" => keepass.db,
251
- "clipboard_timeout" => options["timeout"]
252
- },
253
- "rpass:/> ".white
254
- )
256
+ if (options["command"])
257
+ djinni.grant_wish(
258
+ "#{options["command"].chomp}\n",
259
+ {
260
+ "keepass" => keepass,
261
+ "cwd" => keepass.db,
262
+ "clipboard_timeout" => options["timeout"]
263
+ }
264
+ )
265
+ keepass.wait_to_exit
266
+ else
267
+ djinni.prompt(
268
+ {
269
+ "keepass" => keepass,
270
+ "cwd" => keepass.db,
271
+ "clipboard_timeout" => options["timeout"]
272
+ },
273
+ "rpass:/> ".white
274
+ )
275
+ end
255
276
  exit RPassExit::GOOD
@@ -0,0 +1,123 @@
1
+ require "djinni"
2
+ require "string"
3
+
4
+ class EchoWish < Djinni::Wish
5
+ def aliases
6
+ return [ "echo" ]
7
+ end
8
+
9
+ def description
10
+ return "Echo specified field to stdout"
11
+ end
12
+
13
+ def execute(args, djinni_env = {})
14
+ if (args.nil? || args.empty?)
15
+ puts usage
16
+ return
17
+ end
18
+
19
+ field, args = args.split(" ", 2)
20
+ if (!@fields.include?(field))
21
+ puts usage
22
+ return
23
+ end
24
+
25
+ keepass = djinni_env["keepass"]
26
+ cwd = djinni_env["cwd"]
27
+ args = cwd.path if (args.nil? || args.empty?)
28
+
29
+ args = keepass.absolute_path(args, cwd.path)
30
+ path, target = args.rsplit("/")
31
+ new_cwd = keepass.find_group(path)
32
+
33
+ if (new_cwd)
34
+ if (target.empty?)
35
+ usage
36
+ elsif (new_cwd.has_entry?(target))
37
+ target = new_cwd.entry_titles.select do |entry|
38
+ target.downcase == entry.downcase
39
+ end.first
40
+
41
+ case field
42
+ when "pass"
43
+ new_cwd.entries[target].echo_password
44
+ when "url"
45
+ new_cwd.entries[target].echo_url
46
+ when "user"
47
+ new_cwd.entries[target].echo_username
48
+ end
49
+ else
50
+ puts "Entry \"#{args}\" doesn't exist!"
51
+ end
52
+ else
53
+ puts "Entry \"#{args}\" doesn't exist!"
54
+ end
55
+ end
56
+
57
+ def initialize
58
+ @fields = [ "pass", "url", "user" ]
59
+ end
60
+
61
+ def tab_complete(input, djinni_env = {})
62
+ if (input.nil? || input.empty?)
63
+ puts
64
+ puts @fields
65
+ return ""
66
+ end
67
+
68
+ field, input = input.split(" ", 2)
69
+
70
+ if (input.nil? || input.empty?)
71
+ @fields.each do |f|
72
+ break if (f == field)
73
+ if (f.start_with?(field))
74
+ return "#{f} "
75
+ end
76
+ end
77
+ end
78
+
79
+ input = "" if (input.nil?)
80
+
81
+ cwd = djinni_env["cwd"]
82
+ input, groups, entries = cwd.fuzzy_find(input)
83
+ if (groups.empty? && entries.empty?)
84
+ return "#{field} #{input.gsub(%r{^#{cwd.path}/?}, "")}"
85
+ end
86
+
87
+ path, target = input.rsplit("/")
88
+
89
+ if (target.empty?)
90
+ if ((groups.length == 1) && entries.empty?)
91
+ input = "#{path}/#{groups.first}/"
92
+ return "#{field} #{input.gsub(%r{^#{cwd.path}/?}, "")}"
93
+ elsif (groups.empty? && (entries.length == 1))
94
+ input = "#{path}/#{entries.first}"
95
+ return "#{field} #{input.gsub(%r{^#{cwd.path}/?}, "")}"
96
+ end
97
+ puts
98
+ groups.each do |group|
99
+ puts "#{group}/"
100
+ end
101
+ puts entries
102
+ return "#{field} #{input.gsub(%r{^#{cwd.path}/?}, "")}"
103
+ end
104
+
105
+ if (!groups.empty?)
106
+ input = "#{path}/#{groups.first}/"
107
+ elsif (!entries.empty?)
108
+ input = "#{path}/#{entries.first}"
109
+ end
110
+
111
+ return "#{field} #{input.gsub(%r{^#{cwd.path}/?}, "")}"
112
+ end
113
+
114
+ def usage
115
+ puts "#{aliases.join(", ")} <field> <entry>"
116
+ puts "\t#{description}."
117
+ puts
118
+ puts "FIELDS"
119
+ @fields.each do |field|
120
+ puts "\t#{field}"
121
+ end
122
+ end
123
+ end
data/lib/rubeepass.rb CHANGED
@@ -526,6 +526,11 @@ class RubeePass
526
526
  def to_s
527
527
  return @db.to_s
528
528
  end
529
+
530
+ def wait_to_exit
531
+ return if (@thread.nil?)
532
+ @thread.join
533
+ end
529
534
  end
530
535
 
531
536
  require "rubeepass/entry"
@@ -61,13 +61,32 @@ class RubeePass::Entry
61
61
  def method_missing(method_name, *args)
62
62
  super if (@keepass.nil?)
63
63
 
64
- case method_name.to_s.gsub(/^copy_(.+)_to_clipboard$/, "\\1")
65
- when "password"
66
- @keepass.copy_to_clipboard(password)
67
- when "url"
68
- @keepass.copy_to_clipboard(@url)
69
- when "username"
70
- @keepass.copy_to_clipboard(@username)
64
+ if (method_name.to_s.match(/^copy_.+_to_clipboard$/))
65
+ method_name = method_name.to_s.gsub(
66
+ /^copy_(.+)_to_clipboard$/,
67
+ "\\1"
68
+ )
69
+ case method_name
70
+ when "password"
71
+ @keepass.copy_to_clipboard(password)
72
+ when "url"
73
+ @keepass.copy_to_clipboard(@url)
74
+ when "username"
75
+ @keepass.copy_to_clipboard(@username)
76
+ else
77
+ super
78
+ end
79
+ elsif (method_name.match(/^echo_.+$/))
80
+ case method_name.to_s.gsub(/^echo_/, "")
81
+ when "password"
82
+ puts password
83
+ when "url"
84
+ puts @url
85
+ when "username"
86
+ puts @username
87
+ else
88
+ super
89
+ end
71
90
  else
72
91
  super
73
92
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubeepass
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Whittaker
@@ -121,6 +121,7 @@ files:
121
121
  - lib/builtins/cd_wish.rb
122
122
  - lib/builtins/clear_wish.rb
123
123
  - lib/builtins/copy_wish.rb
124
+ - lib/builtins/echo_wish.rb
124
125
  - lib/builtins/ls_wish.rb
125
126
  - lib/builtins/pwd_wish.rb
126
127
  - lib/builtins/show_all_wish.rb