]> arthur.barton.de Git - ax-zsh.git/commitdiff
New "browser_select" plugin
authorAlexander Barton <alex@barton.de>
Sun, 21 Mar 2021 16:36:16 +0000 (17:36 +0100)
committerAlexander Barton <alex@barton.de>
Sun, 21 Mar 2021 16:40:56 +0000 (17:40 +0100)
plugins/browser_select/README.md [new file with mode: 0644]
plugins/browser_select/browser_select.zprofile [new file with mode: 0644]

diff --git a/plugins/browser_select/README.md b/plugins/browser_select/README.md
new file mode 100644 (file)
index 0000000..c87d842
--- /dev/null
@@ -0,0 +1,10 @@
+## browser_select
+
+Search for the "best" WWW browser and setup environment (`$BROWSER`) accordingly.
+
+The plugin looks for the following WWW browsers and stops at the first one it finds:
+
+
+### Environment
+
+- `$BROWSER`: Command (including parameters) to run a WWW browser.
diff --git a/plugins/browser_select/browser_select.zprofile b/plugins/browser_select/browser_select.zprofile
new file mode 100644 (file)
index 0000000..0f72e74
--- /dev/null
@@ -0,0 +1,29 @@
+# AX-ZSH: Alex' Modular ZSH Configuration
+# browser_select.zprofile: Setup $BROWSER for the "best" available WWW browser
+
+# Don't run this plugin on "check-plugins"!
+[[ -z "$AXZSH_PLUGIN_CHECK" ]] || return 92
+
+
+if [[ -z "$BROWSER" ]]; then
+       if [[ -n "$DISPLAY" ]]; then
+               # X11 available, consider X11-based browsers, too!
+               x11_browsers="firefox chrome"
+       fi
+
+       # Note: We can't use xdg-open(1) here, as xdg-open itself tries to use
+       # $BROWSER, and this would result in an endless loop!
+       for browser (
+               open
+               $x11_browsers
+               elinks w3m links2 links lynx
+       ); do
+               if [ -n "$commands[$browser]" ]; then
+                       BROWSER="$commands[$browser]"
+                       break
+               fi
+       done
+       unset browser x11_browsers
+fi
+
+[[ -n "$BROWSER" ]] && export BROWSER