aboutsummaryrefslogtreecommitdiffstats
path: root/bin/search_duckduckgo
blob: 49f70285d5ee5ab3bbde66a9fbde131150573191 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/usr/bin/env bash
set -e

# @describe Takes in a query string and returns search result from DuckDuckGo.
# Use it to answer user questions that require dates, facts, real-time information, or news.
# This ensures accurate and up-to-date answers.
#
# @meta require-tools ddgr
# @env DDG_MAX_RESULTS=5 The max results to return.
# @option --query! The query to search for.

main() {
    ddgr -n $DDG_MAX_RESULTS --json "$argc_query" | \
    jq -r '. as $input | 
reduce range(0; length) as $i ([]; . + [ $input[$i] | .index = $i ]) |
.[] | "### \(.index+1). \u001b]8;;\(.url)\u001b\\\(.title)\u001b]8;;\u001b\\\n\(.abstract)\n"
'
}

eval "$(argc --argc-eval "$0" "$@")"