55
66import fnmatch
77import os
8+
89from albert import *
910
10- md_iid = "4 .0"
11+ md_iid = "5 .0"
1112md_version = "2.0.1"
1213md_name = "Pass"
1314md_description = "Manage passwords in pass"
2122PASS_DIR = os .environ .get ("PASSWORD_STORE_DIR" , os .path .join (HOME_DIR , ".password-store/" ))
2223
2324
24- class Plugin (PluginInstance , TriggerQueryHandler ):
25+ class Plugin (PluginInstance , GeneratorQueryHandler ):
2526 def __init__ (self ):
2627 PluginInstance .__init__ (self )
27- TriggerQueryHandler .__init__ (self )
28+ GeneratorQueryHandler .__init__ (self )
2829 self ._use_otp = self .readConfig ("use_otp" , bool ) or False
2930 self ._otp_glob = self .readConfig ("otp_glob" , str ) or "*-otp.gpg"
3031
@@ -69,36 +70,36 @@ def configWidget(self):
6970 },
7071 ]
7172
72- def handleTriggerQuery (self , query ):
73- if query .string .strip ().startswith ("generate" ):
74- self .generatePassword (query )
75- elif query .string .strip ().startswith ("otp" ) and self ._use_otp :
76- self .showOtp (query )
73+ def items (self , context : QueryContext ):
74+ q = context .query .strip ()
75+
76+ if q .startswith ("generate" ):
77+ yield [self .generatePassword (q )]
78+ elif q .startswith ("otp" ) and self ._use_otp :
79+ yield self .showOtp (q )
7780 else :
78- self .showPasswords (query )
79-
80- def generatePassword (self , query ):
81- location = query .string .strip ()[9 :]
82-
83- query .add (
84- StandardItem (
85- id = "generate_password" ,
86- icon_factory = Plugin .makeIcon ,
87- text = "Generate a new password" ,
88- subtext = "The new password will be located at %s" % location ,
89- input_action_text = "pass %s" % query .string ,
90- actions = [
91- Action (
92- "generate" ,
93- "Generate" ,
94- lambda : runDetachedProcess (["pass" , "generate" , "--clip" , location , "20" ]),
95- )
96- ],
97- )
81+ yield self .showPasswords (q )
82+
83+ def generatePassword (self , query ) -> Item :
84+ location = query .strip ()[9 :]
85+
86+ return StandardItem (
87+ id = "generate_password" ,
88+ icon_factory = Plugin .makeIcon ,
89+ text = "Generate a new password" ,
90+ subtext = "The new password will be located at %s" % location ,
91+ input_action_text = "pass %s" % query ,
92+ actions = [
93+ Action (
94+ "generate" ,
95+ "Generate" ,
96+ lambda : runDetachedProcess (["pass" , "generate" , "--clip" , location , "20" ]),
97+ )
98+ ],
9899 )
99100
100- def showOtp (self , query ):
101- otp_query = query .string . strip ()[4 :]
101+ def showOtp (self , query ) -> list [ Item ] :
102+ otp_query = query .strip ()[4 :]
102103 passwords = []
103104 if otp_query :
104105 passwords = self .getPasswordsFromSearch (otp_query , otp = True )
@@ -122,11 +123,11 @@ def showOtp(self, query):
122123 ],
123124 ),
124125 )
125- query . add ( results )
126+ return results
126127
127- def showPasswords (self , query ):
128- if query .string . strip ():
129- passwords = self .getPasswordsFromSearch (query . string )
128+ def showPasswords (self , query ) -> list [ Item ] :
129+ if query .strip ():
130+ passwords = self .getPasswordsFromSearch (query )
130131 else :
131132 passwords = self .getPasswords ()
132133
@@ -160,7 +161,7 @@ def showPasswords(self, query):
160161 ),
161162 )
162163
163- query . add ( results )
164+ return results
164165
165166 def getPasswords (self , otp = False ):
166167 passwords = []
0 commit comments