#!/bin/bash

# Copyright Jean-Philippe Guillemin <h1p8r10n@gmail.com>. This program is free software; you can redistribute
# it and/or modify it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or (at your option)
# any later version. Please take a look at http://www.gnu.org/copyleft/gpl.htm

desktop="$(xdg-mime query default x-scheme-handler/http)"

if [[ -e ~/.config/xfce4/helpers.rc ]] ; then
	command=$( grep 'WebBrowser' ~/.config/xfce4/helpers.rc | sed -e 's/^WebBrowser=\(.*\)$/\1/g' )
elif [[ -e ~/.local/share/applications/${desktop} ]] ; then
	command=$(grep 'Exec' ~/.local/share/applications/${desktop} | sed -e 's|^[^=]*=[ \t]*\([^ \t]*\)[ \t]*.*$|\1|g'  )
elif [[ -e /usr/share/applications/${desktop} ]] ; then
	command=$(grep 'Exec' /usr/share/applications/${desktop} | sed -e 's|^[^=]*=[ \t]*\([^ \t]*\)[ \t]*.*$|\1|g'  )
fi

if [ "$(echo -n "$command" | grep 'chromium')" ]; then
	$command --silent-launch &
elif [ "$(echo -n "$command" | grep 'firefox')" ]; then
	$command -silent &
fi
