-
Notifications
You must be signed in to change notification settings - Fork 0
/
sunbeam-extension
executable file
·58 lines (55 loc) · 1.56 KB
/
sunbeam-extension
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
#!/bin/sh
set -e
# if no arguments are passed, return the extension's manifest
if [ $# -eq 0 ]; then
sunbeam query -n '{
title: "DevDocs",
commands: [
{
name: "list-docsets",
title: "List Docsets",
mode: "view"
},
{
name: "list-entries",
title: "List Entries from Docset",
mode: "view",
params: [
{name: "slug", type: "string", required: true, description: "docset to search"}
]
}
]
}'
exit 0
fi
if [ "$1" = "list-docsets" ]; then
# shellcheck disable=SC2016
sunbeam fetch https://devdocs.io/docs/docs.json | sunbeam query 'map({
title: .name,
subtitle: (.release // "latest"),
accessories: [ .slug ],
actions: [
{
title: "Browse entries",
onAction: {
type: "run",
command: "list-entries",
params: {
slug: .slug
}
}
}
]
}) | { type: "list", items: . }'
elif [ "$1" = "list-entries" ]; then
SLUG=$(sunbeam query -r '.params.slug')
# shellcheck disable=SC2016
sunbeam fetch "https://devdocs.io/docs/$SLUG/index.json" | sunbeam query --arg slug="$SLUG" '.entries | map({
title: .name,
subtitle: .type,
actions: [
{title: "Open in Browser", onAction: { type: "open", target: "https://devdocs.io/\($slug)/\(.path)", exit: true}},
{title: "Copy URL", key: "c", onAction: { type: "copy", text: "https://devdocs.io/\($slug)/\(.path)", exit: true}}
]
}) | { type: "list", items: . }'
fi