-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
78 lines (64 loc) · 2.67 KB
/
main.py
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
66
67
68
69
70
71
72
73
74
75
76
77
import sys
from pathlib import Path
plugindir = Path.absolute(Path(__file__).parent)
paths = (".", "lib", "plugin")
sys.path = [str(plugindir / p) for p in paths] + sys.path
import json
from flowlauncher import FlowLauncher
import webbrowser
def load_vim_commands(file_path):
"""Load Vim commands from a JSON file."""
with open(file_path, 'r') as file:
return json.load(file)
vim_commands = load_vim_commands('db/commands.json')
# vim_commands = load_vim_commands('commands.Not_url_encoded.json')
icon_path = "src/icon.png"
class VimCheatSheet(FlowLauncher):
def query(self, query):
# """Search for Vim commands matching the user query."""
results = []
query_lower = query.lower() # Convert query to lowercase for case-insensitive matching
for command in vim_commands:
if any(keyword.startswith(query_lower) or query_lower == keyword for keyword in command["keywords"]):
# if any(keyword in query_lower for keyword in command["keywords"]):
results.append({
"Title": f"{command['command']}",
"SubTitle": f"{command['name']} | {command['description']}",
"IcoPath": icon_path,
# "ContextData": ["foo", "bar"],
"JsonRPCAction": {
"method": "open_url",
"parameters": [f"https://vim.rtorr.com/#:~:text={command['rtorr_description']}"],
"dontHideAfterAction": False
}
})
# print(results)
# Fallback if no match is found
if not results:
results.append({
"Title": "No match found",
"SubTitle": "Try searching for a different Vim command",
"IcoPath": icon_path,
"JsonRPCAction": {
"method": "open_url",
"parameters": ["https://github.com/MoAlSeifi/Flow.Launcher.Plugin.VimCheatSheet"],
"dontHideAfterAction": False
}
})
return results
# def context_menu(self, data):
# return [
# {
# "Title": {data["name"]},
# "SubTitle": "Press enter to open Flow the plugin's repo in GitHub",
# "IcoPath": "Images/app.png",
# "JsonRPCAction": {
# "method": "open_url",
# "parameters": ["https://github.com/Flow-Launcher/Flow.Launcher.Plugin.HelloWorldPython"]
# }
# }
# ]
def open_url(self, url):
webbrowser.open(url)
if __name__ == "__main__":
VimCheatSheet()