old-dotfiles/bin/search_open

23 lines
546 B
Bash
Executable File

#!/bin/bash
QUERY=$@
if [[ -z $QUERY ]]; then
QUERY=$(dmenu -p "Search Query: " < /dev/null )
fi
[[ -n $QUERY ]] || exit
QUERY=$(echo $QUERY | sed 's/ /+/g')
RESULT=$(curl "http://s.herisson.ovh/search?q=$QUERY&format=json")
TITLES=$(echo "$RESULT" | jq -r '.results[] | .title')
LINKS=$(echo "$RESULT" | jq -r '.results[] | .url')
SELECT=$(paste -d ": " <(seq $(echo "$TITLES" | wc -l)) <(echo "$TITLES") <(echo "$LINKS")| dmenu -l 15 | cut -d: -f1)
[[ -n $SELECT ]] || exit
echo "$LINKS" | head -n $SELECT | tail -1 | xargs xdg-open