From 6833d840778897b2304195b13ac75d2a96c08a72 Mon Sep 17 00:00:00 2001 From: Anders Damsgaard Date: Wed, 19 Dec 2018 10:18:29 +0100 Subject: [PATCH 1/3] Detect http urls in query and directly connect to them --- .scripts/i3cmds/ducksearch | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/.scripts/i3cmds/ducksearch b/.scripts/i3cmds/ducksearch index 13a1e19..2f09675 100755 --- a/.scripts/i3cmds/ducksearch +++ b/.scripts/i3cmds/ducksearch @@ -1,15 +1,18 @@ #!/bin/sh -# Gives a dmenu prompt to search DuckDuckGo. -# Without input, will open DuckDuckGo.com. -# Anything else, it search it. +browser=${BROWSER:-firefox} pgrep -x dmenu && exit -choice=$(echo "🦆" | dmenu -i -p "Search DuckDuckGo:") || exit 1 +query=$(echo "duckduckgo.com" | dmenu -i -p "Search DuckDuckGo:") || exit 1 -if [ "$choice" = "🦆" ]; then - $BROWSER "https://duckduckgo.com" +if [ "$query" = "duckduckgo.com" ]; then + $browser "https://duckduckgo.com" else - $BROWSER "https://duckduckgo.com/?q=$choice&t=ffab&atb=v1-1" + # Detect if url + if [[ "$query" =~ ^(http:\/\/|https:\/\/)?[a-zA-Z0-9]+.[a-zA-Z]+(/)?.*$ ]]; then + $browser "$query" + else + $browser "https://duckduckgo.com/?q=$query&t=ffab&atb=v1-1" + fi fi From ca12ed28a5bfe028463921cb65958a1cf4a66fdb Mon Sep 17 00:00:00 2001 From: Anders Damsgaard Date: Wed, 19 Dec 2018 10:28:09 +0100 Subject: [PATCH 2/3] Revert unneeded changes --- .scripts/i3cmds/ducksearch | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/.scripts/i3cmds/ducksearch b/.scripts/i3cmds/ducksearch index 2f09675..2e14513 100755 --- a/.scripts/i3cmds/ducksearch +++ b/.scripts/i3cmds/ducksearch @@ -1,18 +1,22 @@ #!/bin/sh +# 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 -query=$(echo "duckduckgo.com" | dmenu -i -p "Search DuckDuckGo:") || exit 1 +choice=$(echo "🦆" | dmenu -i -p "Search DuckDuckGo:") || exit 1 -if [ "$query" = "duckduckgo.com" ]; then +if [ "$choice" = "🦆" ]; then $browser "https://duckduckgo.com" else # Detect if url - if [[ "$query" =~ ^(http:\/\/|https:\/\/)?[a-zA-Z0-9]+.[a-zA-Z]+(/)?.*$ ]]; then - $browser "$query" + if [[ "$choice" =~ ^(http:\/\/|https:\/\/)?[a-zA-Z0-9]+.[a-zA-Z]+(/)?.*$ ]]; then + $browser "$choice" else - $browser "https://duckduckgo.com/?q=$query&t=ffab&atb=v1-1" + $browser "https://duckduckgo.com/?q=$choice&t=ffab&atb=v1-1" fi fi From 69296d87d7d1f4aa1b1c6f9a4cb7f571036bb388 Mon Sep 17 00:00:00 2001 From: Anders Damsgaard Date: Wed, 19 Dec 2018 10:32:00 +0100 Subject: [PATCH 3/3] Parse dot as period, not character wildcard --- .scripts/i3cmds/ducksearch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.scripts/i3cmds/ducksearch b/.scripts/i3cmds/ducksearch index 2e14513..4e79570 100755 --- a/.scripts/i3cmds/ducksearch +++ b/.scripts/i3cmds/ducksearch @@ -14,7 +14,7 @@ if [ "$choice" = "🦆" ]; then $browser "https://duckduckgo.com" else # Detect if url - if [[ "$choice" =~ ^(http:\/\/|https:\/\/)?[a-zA-Z0-9]+.[a-zA-Z]+(/)?.*$ ]]; then + if [[ "$choice" =~ ^(http:\/\/|https:\/\/)?[a-zA-Z0-9]+\.[a-zA-Z]+(/)?.*$ ]]; then $browser "$choice" else $browser "https://duckduckgo.com/?q=$choice&t=ffab&atb=v1-1"