#!/bin/sh
#
# bro - launch $BROWSER with any given arguments

if command -v browser >/dev/null; then
  BROWSER="browser"
elif is-mac; then
  BROWSER=${BROWSER:-open}
else
  BROWSER=${BROWSER:-lynx}
fi

nohup "${BROWSER}" "$@" >/dev/null 2>/dev/null

# # b - trivial commandline browser

# tmpdir=$(mktemp -d "${TMPDIR:-/tmp}"/"$(basename "$0")".XXXXXX) || return
# USER=${USERNAME:-$(/usr/bin/id -u -n)}

# STORE="${tmpdir}/b-$(hostname).${USER}"

# case "${TERM}" in
#   9term|win) PAGER="cat" ;;
#   *) PAGER="less"; export LESS=-FX ;;
# esac

# # shellcheck disable=SC2312
# case "$1" in
#     [0-9]*)
#         $0 "$(awk '/^References/,0' <"${STORE}" |
#               awk -v n="$1" '$1 == n { print $2 }')" ;;
#     */*|*.*)
#         echo "$1" >"${STORE}".url
#         lynx --dump "$1" | tee "${STORE}" | ${PAGER} ;;
#     -e*) elinks "$(cat "${STORE}".url)" ;;
#     -f*) firefox "$(cat "${STORE}".url)" ;;
#     -l*) lynx "$(cat "${STORE}".url)" ;;
#     -w*) w3m "$(cat "${STORE}".url)" ;;
#     ?*)
#         if [ -x /usr/lib/surfraw/"$1" ]; then
#           SURFRAW_browser=$0 sr "$@"
#         else
#                                     # /search?ie=utf-8&q=s
#           # $0 "https://www.google.com/search?ie=utf-8&oe=utf-8&q=$*"
#           $0 "https://duckduckgo.com/?ie=utf-8&oe=utf-8&q=$*"
#         fi ;;
#     *)
#         # empty
#         ${PAGER} "${STORE}" 2>/dev/null
# esac
