Over the weekend, I picked up a project via Reddit involving a plugin for the Flow Launcher. I created a fzf and rofi version for my Ubuntu Linux environment, and then thought, how hard can it be to port it to uLauncher?
Here I document what I did.
1. Inside ~/.local/share/ulauncher/extensions/
create a new dir. In my case, I created ~/.local/share/ulauncher/extensions/com.github.ubuntupunk.ulauncher-vim
2. Touch the following files:
├── images │ └── icon.png ├── versions.json ├── manifest.json └── main.py
3. In versions.json place the following boilerplate:
[ {"required_api_version": "2", "commit": "master"} ]
4. In manifest.json
{ "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" } ] }
5. In main.py
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()
6. Now edit manifest.json
{ "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" } ]
7. Add command loading function to main.py
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())
8. Create a db folder with the following:
commands.json
example structure:
{ "categories": { "navigation": { "name": "Navigation", "patterns": [ "scroll", "jump", "goto", "position" ], "subcategories": { "cursor": { "name": "Cursor Movement", "patterns": [ "move[s]? cursor", "^[hjkl]$", "^[HJKL]$", "^[wWeEbB]$" ] },
You can see the entire commands.json here.
9. Modify the KeywordQueryEventListener to implement the search functionality.
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)
10. Add the URL opening functionality. We'll need to import webbrowser and modify the on_enter action to open the Vim command URL
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)
11. Key changes are:
- Added OpenUrlAction import
- Replaced HideWindowAction with OpenUrlAction
- Constructed the URL using the command's rtorr_description
12. The full project code can be viewed here:
ulauncher-vim repo
and the ulauncher extension here
References
- https://dev.to/brpaz/an-introduction-to-ulauncher-extension-development-1m69
- https://ext.ulauncher.io/-/github-ubuntupunk-ulauncher-vim
The above is the detailed content of Develop a ulauncher extension with a command database. For more information, please follow other related articles on the PHP Chinese website!

InPython,youappendelementstoalistusingtheappend()method.1)Useappend()forsingleelements:my_list.append(4).2)Useextend()or =formultipleelements:my_list.extend(another_list)ormy_list =[4,5,6].3)Useinsert()forspecificpositions:my_list.insert(1,5).Beaware

The methods to debug the shebang problem include: 1. Check the shebang line to make sure it is the first line of the script and there are no prefixed spaces; 2. Verify whether the interpreter path is correct; 3. Call the interpreter directly to run the script to isolate the shebang problem; 4. Use strace or trusts to track the system calls; 5. Check the impact of environment variables on shebang.

Pythonlistscanbemanipulatedusingseveralmethodstoremoveelements:1)Theremove()methodremovesthefirstoccurrenceofaspecifiedvalue.2)Thepop()methodremovesandreturnsanelementatagivenindex.3)Thedelstatementcanremoveanitemorslicebyindex.4)Listcomprehensionscr

Pythonlistscanstoreanydatatype,includingintegers,strings,floats,booleans,otherlists,anddictionaries.Thisversatilityallowsformixed-typelists,whichcanbemanagedeffectivelyusingtypechecks,typehints,andspecializedlibrarieslikenumpyforperformance.Documenti

Pythonlistssupportnumerousoperations:1)Addingelementswithappend(),extend(),andinsert().2)Removingitemsusingremove(),pop(),andclear().3)Accessingandmodifyingwithindexingandslicing.4)Searchingandsortingwithindex(),sort(),andreverse().5)Advancedoperatio

Create multi-dimensional arrays with NumPy can be achieved through the following steps: 1) Use the numpy.array() function to create an array, such as np.array([[1,2,3],[4,5,6]]) to create a 2D array; 2) Use np.zeros(), np.ones(), np.random.random() and other functions to create an array filled with specific values; 3) Understand the shape and size properties of the array to ensure that the length of the sub-array is consistent and avoid errors; 4) Use the np.reshape() function to change the shape of the array; 5) Pay attention to memory usage to ensure that the code is clear and efficient.

BroadcastinginNumPyisamethodtoperformoperationsonarraysofdifferentshapesbyautomaticallyaligningthem.Itsimplifiescode,enhancesreadability,andboostsperformance.Here'showitworks:1)Smallerarraysarepaddedwithonestomatchdimensions.2)Compatibledimensionsare

ForPythondatastorage,chooselistsforflexibilitywithmixeddatatypes,array.arrayformemory-efficienthomogeneousnumericaldata,andNumPyarraysforadvancednumericalcomputing.Listsareversatilebutlessefficientforlargenumericaldatasets;array.arrayoffersamiddlegro


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Atom editor mac version download
The most popular open source editor

WebStorm Mac version
Useful JavaScript development tools
