#!/bin/bash

POSITIONAL_ARGS=()

while [[ $# -gt 0 ]]; do
  case $1 in
    --*)
      POSITIONAL_ARGS+=("$1")
      shift
      ;;
    -*)
      POSITIONAL_ARGS+=("-$1")
      shift
      ;;
    *)
      POSITIONAL_ARGS+=("$1")
      shift
      ;;
  esac
done

POSITIONAL_ARGS+=(
  "--marionette"
  "--preferences"
)
set -- "${POSITIONAL_ARGS[@]}" # restore positional parameters

if which firefox >/dev/null 2>/dev/null; then
  exec firefox "$@"
elif which librewolf >/dev/null 2>/dev/null; then
  # not first pick due to it dying somehow randomly
  exec librewolf "$@"
else
  echo "No Supported Browser!" 1>&2;
  exit 1
fi