summaryrefslogtreecommitdiff
path: root/qutebrowser/userscripts/url-from-surfraw
blob: 9bd67951fc981e8b7af8fb81aa35ebf29afe547d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/usr/bin/env bash

DEFAULT_SEARCH=startpage

if [[ $1 =~ ^-.$ ]]; then
    option="$1"
    shift 1
fi

is_elvi=$(surfraw -elvi | grep -c "^$1\s")
nbr_words=$(echo $1 | wc -w)

if [[ $is_elvi -eq 0 && $nbr_words -eq 1 && ($1 == *.* || $1 == *:*) ]]; then
    url="$1"
else 
    [[ $is_elvi -eq 0 ]] && sr="$DEFAULT_SEARCH $*" || sr=$*
    url=$(surfraw -print $sr)
fi

echo "open $option $url" >> $QUTE_FIFO