-
Notifications
You must be signed in to change notification settings - Fork 0
/
source.py
51 lines (37 loc) · 1.12 KB
/
source.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
from typing import Optional
import vscode
ext = vscode.Extension(
"internet-search",
"Internet Search",
"0.0.1",
"Use your default browser to search anything quickly",
"./icon.png",
{"type": "git", "url": "https://github.com/Dorukyum/internet-search"},
"Dorukyum",
)
ext.set_default_category("Search")
@ext.command("DuckDuckGo")
def duckduckgo() -> None:
command("duckduckgo", "")
@ext.command("Google")
def google() -> None:
command("google", "search")
@ext.command("Bing")
def bing() -> None:
command("bing", "search")
def command(engine, path) -> None:
query: Optional[str] = None
editor = vscode.window.ActiveTextEditor()
if editor != vscode.ext.undefined:
selection = editor.document.get_text(editor.selection)
if selection:
query = selection
query = query or vscode.window.show_input_box(
vscode.ext.InputBoxOptions("What would you like to search for?")
)
if not query:
return
vscode.env.open_external(
f"https://www.{engine}.com/{path}?q={query.replace(' ', '+')}"
)
vscode.build(ext, publish=True)