aboutsummaryrefslogtreecommitdiff
path: root/X
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2018-11-22 22:33:59 +1300
committerTom Ryder <tom@sanctum.geek.nz>2018-11-22 22:33:59 +1300
commit4cb0b580b2679f40ccc31f42a360c28c14a1e59d (patch)
tree2d90ff2abf520a9c705d0c0d8c109876f385b67f /X
parent2c50366c35a145f834417c1ef1ef5a5dfd6986ed (diff)
downloaddotfiles-4cb0b580b2679f40ccc31f42a360c28c14a1e59d.tar.gz
dotfiles-4cb0b580b2679f40ccc31f42a360c28c14a1e59d.zip
Apply some logic to choose a GUI browser
I'll want to use Dillo if I'm on a machine with limited memory, but the balance tips in favour of Firefox if I have RAM to spare.
Diffstat (limited to 'X')
-rw-r--r--X/xinitrc.d/browser.sh26
1 files changed, 23 insertions, 3 deletions
diff --git a/X/xinitrc.d/browser.sh b/X/xinitrc.d/browser.sh
index cdb9b8c0..0153fba9 100644
--- a/X/xinitrc.d/browser.sh
+++ b/X/xinitrc.d/browser.sh
@@ -1,4 +1,24 @@
-# Browser within X is Firefox
-command -v firefox >/dev/null 2>&1 || return
-BROWSER=firefox
+# Choose a GUI browser with some rough heuristics
+
+# If Firefox is available, start by assuming that
+if command -v firefox >/dev/null 2>&1 ; then
+ BROWSER=firefox
+fi
+
+# Consider a switch to Dillo...
+if (
+ # No output, please
+ exec >/dev/null 2>&1
+ # Don't switch if it's not there
+ command -v dillo || exit
+ # Switch if Firefox isn't there
+ command -v firefox || exit 0
+ # Switch if procfs says we have less than 2GB of RAM
+ awk '$1=="MemTotal:"&&$2<2^20{m++}END{exit!m}' < /proc/meminfo
+) ; then
+ BROWSER=dillo
+fi
+
+# Export our choice of browser, if it isn't empty
+[ -n "$BROWSER" ] || return
export BROWSER