#!/bin/sh

# SEARCH_BASE='https://duckduckgo.com/?q='
# SEARCH_BASE='https://html.duckduckgo.com/html/?q='
SEARCH_BASE='https://lite.duckduckgo.com/lite?kae=t&q='

if echo "$1" | grep -Eq '^http[s]?://'; then
  # just open has issues with url formatting
  echo "$1" | xargs open
  echo "🔗 $1"
elif echo "$1" | grep -Eq '^git@github.com:'; then
  echo "$1" | sed 's|^git@github.com:|https://github.com/|;s|.git$||' | xargs open
  echo "🔗 $1"
else
  echo "${SEARCH_BASE}$1" | sed 's| |+|g' | xargs open
  echo "🔍 $1"
fi
