forked from samueldeng/alfred-keepass
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathalfred_workflow.rb
65 lines (52 loc) · 1.38 KB
/
alfred_workflow.rb
1
2
3
4
5
6
7
8
9
10
11
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
61
62
63
64
65
# encoding: utf-8
class AlfredXmlFormatter
def initialize()
@keepass_items = []
end
def add_kp(kp)
@keepass_items << kp
end
def to_string()
kp_item_template =
'<item uid="home" valid="YES" autocomplete="Home Folder" type="file">
<title>%s</title>
<subtitle>%s ******</subtitle>
<icon type="fileicon">~/</icon>
<arg>%s</arg>
</item>'
string_buffer = ''
@keepass_items.each { |kp|
string_buffer += kp_item_template % [kp.title, kp.username, kp.password]
}
xml_template =
'<?xml version="1.0" encoding="UTF-8"?>
<items>
%s
</items>'
return xml_template % [string_buffer]
end
end
class KeepassItem
def initialize(title, username, password)
@title = title
@username = username
@password = password
end
def title
@title
end
def username
@username
end
def password
@password
end
end
# kp_i_1 = KeepassItem.new("小木虫", "samueldeng", "222222")
# kp_i_2 = KeepassItem.new("小木虫2", "samueldeng2", "33333")
# kp_i_3 = KeepassItem.new("小木虫3", "samueldeng3", "44444")
# alfred_xml = AlfredXmlFormatter.new
# alfred_xml.add_kp(kp_i_1)
# alfred_xml.add_kp(kp_i_2)
# alfred_xml.add_kp(kp_i_3)
# puts alfred_xml.to_string