voidrice/.scripts/i3cmds/ducksearch

23 lines
596 B
Text
Raw Normal View History

#!/bin/sh
2018-12-19 09:28:09 +00:00
# Gives a dmenu prompt to search DuckDuckGo.
# Without input, will open DuckDuckGo.com.
# URLs will be directly handed to the browser.
# Anything else, it search it.
browser=${BROWSER:-firefox}
pgrep -x dmenu && exit
2018-12-19 09:28:09 +00:00
choice=$(echo "🦆" | dmenu -i -p "Search DuckDuckGo:") || exit 1
2018-12-19 09:28:09 +00:00
if [ "$choice" = "🦆" ]; then
$browser "https://duckduckgo.com"
else
# Detect if url
if [[ "$choice" =~ ^(http:\/\/|https:\/\/)?[a-zA-Z0-9]+\.[a-zA-Z]+(/)?.*$ ]]; then
2018-12-19 09:28:09 +00:00
$browser "$choice"
else
2018-12-19 09:28:09 +00:00
$browser "https://duckduckgo.com/?q=$choice&t=ffab&atb=v1-1"
fi
fi