Skip to content

Commit

Permalink
add google search extension
Browse files Browse the repository at this point in the history
  • Loading branch information
pomdtr committed Nov 7, 2023
1 parent c82e52f commit 22659d5
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 8 deletions.
2 changes: 1 addition & 1 deletion docs/reference/schemas/list.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

```json
{
// the list of items to display (required)
// the list of items to display (optional)
"items": [
{
// title of the item (required)
Expand Down
41 changes: 41 additions & 0 deletions extensions/google.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/sh

set -eu

if [ $# -eq 0 ]; then
sunbeam query -n '{
title: "Google Search",
commands: [
{
name: "search",
mode: "list",
title: "Search",
}
]
}'
exit 0
fi

COMMAND=$(echo "$1" | sunbeam query -r '.command')
if [ "$COMMAND" = "search" ]; then
QUERY=$(echo "$1" | sunbeam query -r '.query')
if [ "$QUERY" = "null" ]; then
sunbeam query -n '{
dynamic: true,
emptyText: "Type something to search",
}'
exit 0
fi
sunbeam fetch "https://suggestqueries.google.com/complete/search?client=firefox&q=$QUERY" | sunbeam query '.[1] | {
dynamic: true,
items: map({
title: .,
actions: [
{ title: "Search", type: "open", target: "https://www.google.com/search?q=\(.)" }
]
})
}'
else
echo "Unknown command: $COMMAND" >&2
exit 1
fi
3 changes: 0 additions & 3 deletions pkg/schemas/list.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"additionalProperties": false,
"required": [
"items"
],
"properties": {
"emptyText": {
"type": "string"
Expand Down
4 changes: 2 additions & 2 deletions pkg/typescript/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/typescript/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sunbeam-types",
"version": "0.23.25",
"version": "0.23.26",
"description": "Types for sunbeam",
"types": "dist/mod.d.ts",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion pkg/typescript/src/page.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Action } from "./action";

export type List = {
items: ListItem[];
items?: ListItem[];
actions?: Action[];
emptyText?: string;
dynamic?: boolean;
Expand Down

0 comments on commit 22659d5

Please sign in to comment.