install.fairie/home/.chezmoiscripts/universal/run_onchange_after_45-default-browser.sh.tmpl

39 lines
2.2 KiB
Cheetah
Raw Normal View History

2023-06-04 18:35:17 -07:00
{{- if ne .host.distro.family "windows" -}}
#!/usr/bin/env bash
# @file Set Default Browser
# @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.
{{ includeTemplate "universal/profile" }}
{{ includeTemplate "universal/logg" }}
2023-06-04 18:35:17 -07:00
if [ -d /Applications ] && [ -d /System ]; then
if ! command -v defaultbrowser > /dev/null; then
2023-11-04 18:46:18 -07:00
logg info 'Installing defaultbrowser via Homebrew which is the preferred way of configuring the default browser'
2023-06-04 18:35:17 -07:00
brew install defaultbrowser
fi
2023-06-14 18:04:11 -07:00
logg info "Setting default browser to {{ .user.defaultBrowserDarwin }}"
defaultbrowser "{{ .user.defaultBrowserDarwin }}"
2023-06-04 18:35:17 -07:00
else
2023-11-04 18:46:18 -07:00
logg info 'Setting default browser for text/html to {{ .user.defaultBrowser }}'
2023-06-04 18:35:17 -07:00
xdg-mime default {{ .user.defaultBrowser }}.desktop text/html
2023-11-04 18:46:18 -07:00
logg info 'Setting default browser for x-scheme-handler/http to {{ .user.defaultBrowser }}'
2023-06-04 18:35:17 -07:00
xdg-mime default {{ .user.defaultBrowser }}.desktop x-scheme-handler/http
2023-11-04 18:46:18 -07:00
logg info 'Setting default browser for x-scheme-handler/https to {{ .user.defaultBrowser }}'
2023-06-04 18:35:17 -07:00
xdg-mime default {{ .user.defaultBrowser }}.desktop x-scheme-handler/https
2023-11-04 18:46:18 -07:00
logg info 'Setting default browser for x-scheme-handler/about to {{ .user.defaultBrowser }}'
2023-06-04 18:35:17 -07:00
xdg-mime default {{ .user.defaultBrowser }}.desktop x-scheme-handler/about
2023-11-04 18:46:18 -07:00
logg info 'Setting default browser with xdg-settings to {{ .user.defaultBrowser }}'
2023-06-04 18:35:17 -07:00
xdg-settings set default-web-browser {{ .user.defaultBrowser }}.desktop
fi
2023-06-09 21:49:29 -07:00
{{ end -}}