Pada hujung minggu, saya mengambil projek melalui Reddit yang melibatkan pemalam untuk Flow Launcher. Saya mencipta versi fzf dan rofi untuk persekitaran Linux Ubuntu saya, dan kemudian berfikir, betapa sukarnya untuk memindahkannya ke uLauncher?
Di sini saya mendokumentasikan perkara yang saya lakukan.
buat dir baharu. Dalam kes saya, saya mencipta ~/.local/share/ulauncher/extensions/com.github.ubuntupunk.ulauncher-vim
├── images │ └── icon.png ├── versions.json ├── manifest.json └── main.py
[ {"required_api_version": "2", "commit": "master"} ]
{ "required_api_version": "2", "name": "Demo extension", "description": "Extension Description", "developer_name": "John Doe", "icon": "images/icon.png", "options": { "query_debounce": 0.1 }, "preferences": [ { "id": "demo_kw", "type": "keyword", "name": "Demo", "description": "Demo extension", "default_value": "dm" } ] }
from ulauncher.api.client.Extension import Extension from ulauncher.api.client.EventListener import EventListener from ulauncher.api.shared.event import KeywordQueryEvent, ItemEnterEvent from ulauncher.api.shared.item.ExtensionResultItem import ExtensionResultItem from ulauncher.api.shared.action.RenderResultListAction import RenderResultListAction from ulauncher.api.shared.action.HideWindowAction import HideWindowAction class DemoExtension(Extension): def __init__(self): super().__init__() self.subscribe(KeywordQueryEvent, KeywordQueryEventListener()) class KeywordQueryEventListener(EventListener): def on_event(self, event, extension): items = [] for i in range(5): items.append(ExtensionResultItem(icon='images/icon.png', name='Item %s' % i, description='Item description %s' % i, on_enter=HideWindowAction())) return RenderResultListAction(items) if __name__ == '__main__': DemoExtension().run()
{ "required_api_version": "2", "name": "Vim Prompter", "description": "Vim cheatsheet helper", "developer_name": "David Robert Lewis", "icon": "images/icon.png", "options": { "query_debounce": 0.1 }, "preferences": [ { "id": "vm_kw", "type": "keyword", "name": "Vim", "description": "Search for Vim commands", "default_value": "vm" } ]
class VmExtension(Extension): def load_vim_commands(self): """Load Vim commands from JSON file.""" package_dir = os.path.dirname(os.path.abspath(__file__)) full_path = os.path.join(package_dir, 'db', 'commands.json') with open(full_path, 'r') as file: return json.load(file) def __init__(self): super().__init__() self.vim_commands = self.load_vim_commands() self.subscribe(KeywordQueryEvent, KeywordQueryEventListener())
commands.json
contoh struktur:
{ "categories": { "navigation": { "name": "Navigation", "patterns": [ "scroll", "jump", "goto", "position" ], "subcategories": { "cursor": { "name": "Cursor Movement", "patterns": [ "move[s]? cursor", "^[hjkl]$", "^[HJKL]$", "^[wWeEbB]$" ] },
Anda boleh melihat keseluruhan commands.json di sini.
class KeywordQueryEventListener(EventListener): def on_event(self, event, extension): query = event.get_argument() or "" items = [] # If no query, show all commands (limited to first 8) commands_to_show = extension.vim_commands # If there's a query, filter commands if query: commands_to_show = [ cmd for cmd in extension.vim_commands if query.lower() in cmd['command'].lower() or query.lower() in cmd['description'].lower() ] # Limit results to first 8 matches for cmd in commands_to_show[:8]: items.append(ExtensionResultItem( icon='images/icon.png', name=cmd['command'], description=f"{cmd['name']} - {cmd['description']}", on_enter=HideWindowAction() )) return RenderResultListAction(items)
from ulauncher.api.shared.action.OpenUrlAction import OpenUrlAction class KeywordQueryEventListener(EventListener): def on_event(self, event, extension): query = event.get_argument() or "" items = [] commands_to_show = extension.vim_commands if query: commands_to_show = [ cmd for cmd in extension.vim_commands if query.lower() in cmd['command'].lower() or query.lower() in cmd['description'].lower() ] for cmd in commands_to_show[:8]: url = f"https://vim.rtorr.com/#:~:text={cmd['rtorr_description']}" items.append(ExtensionResultItem( icon='images/icon.png', name=cmd['command'], description=f"{cmd['name']} - {cmd['description']}", on_enter=OpenUrlAction(url) )) return RenderResultListAction(items)
ulauncher-vim repo
dan sambungan ulauncher di sini
Atas ialah kandungan terperinci Membangunkan sambungan ulauncher dengan pangkalan data arahan. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!