77"""
88
99
10- from albert import *
11- import os
12- import pathlib
1310import shlex
1411import subprocess
12+ from pathlib import Path
13+
14+ from albert import *
1515
16- md_iid = '1 .0'
17- md_version = "1.8 "
16+ md_iid = '2 .0'
17+ md_version = "1.9 "
1818md_name = "Locate"
1919md_description = "Find and open files using locate"
2020md_license = "BSD-3"
2424
2525class Plugin (TriggerQueryHandler ):
2626
27- def id (self ):
28- return md_id
29-
30- def name (self ):
31- return md_name
32-
33- def description (self ):
34- return md_description
35-
36- def defaultTrigger (self ):
37- return "'"
38-
39- def synopsis (self ):
40- return "<locate params>"
27+ def __init__ (self ):
28+ TriggerQueryHandler .__init__ (self ,
29+ id = md_id ,
30+ name = md_name ,
31+ description = md_description ,
32+ synopsis = '<locate params>' ,
33+ defaultTrigger = "'" )
34+ PluginInstance .__init__ (self , extensions = [self ])
4135
42- def initialize (self ):
43- self .icons = [
36+ self .iconUrls = [
4437 "xdg:preferences-system-search" ,
4538 "xdg:system-search" ,
4639 "xdg:search" ,
4740 "xdg:text-x-generic" ,
48- str ( pathlib . Path (__file__ ).parent / " locate.svg")
41+ f"file: { Path (__file__ ).parent } / locate.svg"
4942 ]
5043
5144 def handleTriggerQuery (self , query ):
@@ -64,25 +57,24 @@ def handleTriggerQuery(self, query):
6457 return
6558
6659 for path in lines :
67- basename = os .path .basename (path )
6860 query .add (
69- Item (
61+ StandardItem (
7062 id = path ,
71- text = basename ,
63+ text = Path ( path ). name ,
7264 subtext = path ,
73- icon = self .icons ,
65+ iconUrls = self .iconUrls ,
7466 actions = [
7567 Action ("open" , "Open" , lambda p = path : openUrl ("file://%s" % p ))
7668 ]
7769 )
7870 )
7971 else :
8072 query .add (
81- Item (
73+ StandardItem (
8274 id = "updatedb" ,
8375 text = "Update locate database" ,
8476 subtext = "Type at least three chars for a search" ,
85- icon = self .icons ,
77+ iconUrls = self .iconUrls ,
8678 actions = [
8779 Action ("update" , "Update" , lambda : runTerminal ("sudo updatedb" ))
8880 ]
0 commit comments