summaryrefslogtreecommitdiffstats
path: root/examples/tools/search.sh
blob: a7d05dcd31447a9726e925c7446204799a0ee0a1 (plain)
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
#!/bin/bash
# desktop-assistant tool: web search through a SearXNG instance.
# Copyright (C) 2026 Danilo M. <danix@danix.xyz>
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 as published
# by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# search.sh QUERY: prints the top 5 results as "title: snippet".
# Needs SEARXNG_URL (config.toml [env]) with the JSON format enabled.

set -uo pipefail

[ -n "${SEARXNG_URL:-}" ] || { echo "SEARXNG_URL is not set" >&2; exit 1; }
[ -n "${1:-}" ] || { echo "empty query" >&2; exit 1; }

curl -fsS --max-time 8 --get "$SEARXNG_URL/search" \
        --data-urlencode "q=$1" --data-urlencode "format=json" \
    | jq -r '.results[:5][] | "\(.title): \(.content // "")"' \
    || { echo "search failed" >&2; exit 1; }