# @brief Sets default browser to value managed in `.chezmoi.yaml.tmpl`
# @description
# This script sets the default browser to the value stored in [`.chezmoi.yaml.tmpl`](https://github.com/megabyte-labs/install.doctor/tree/master/home/.chezmoi.yaml.tmpl)
# under the `user` section.
#
# * On macOS, it uses the `defaultbrowser` Homebrew package to update the default browser.
# * On Linux, it uses a combination of `xdg-mime` and `xdg-settings` options to update the default browser.
#
# The default browser for terminal applications is stored as the `BROWSER` value which is
# defined at the end of the [`exports.sh.tmpl`](https://github.com/megabyte-labs/install.doctor/tree/master/home/dot_config/shell/exports.sh.tmpl)
# file. This value is also populated from the `.chezmoi.yaml.tmpl` value.
if [ -d /Applications ] && [ -d /System ]; then
if ! command -v defaultbrowser > /dev/null; then
logg info 'Installing `defaultbrowser` via Homebrew which is the preferred way of configuring the default browser'
brew install defaultbrowser
fi
logg info "Setting default browser to {{ .user.defaultBrowser }}"
defaultbrowser "{{ .user.defaultBrowser }}"
else
logg info 'Setting default browser for `text/html` to `{{ .user.defaultBrowser }}`'