#!/bin/sh

set -eu

if [ -n "${SSH_CLIENT:-}" ]; then
  exec pbd -o "$@"
fi

case "$1" in
  *.gif | *.jpeg | *.jpg | *.png)
    curl -LSs "$1" | imv -
    ;;
  https://youtu.be/* | https://www.youtube.com/watch* | https://twitch.tv/*)
    ulimit -c 0 # mpv segfaults on exit every time on OpenBSD...
    exec mpv "$1" >/dev/null 2>&1
    ;;
  *)
    exec firefox -new-tab "$1" >/dev/null 2>&1
    ;;
esac
