summaryrefslogtreecommitdiff
path: root/modules/host-environment.el
diff options
context:
space:
mode:
Diffstat (limited to 'modules/host-environment.el')
-rw-r--r--modules/host-environment.el48
1 files changed, 48 insertions, 0 deletions
diff --git a/modules/host-environment.el b/modules/host-environment.el
new file mode 100644
index 00000000..649cabe5
--- /dev/null
+++ b/modules/host-environment.el
@@ -0,0 +1,48 @@
+;;; host-environment.el --- Host Environment Convenience Functions -*- lexical-binding: t; -*-
+
+;;; Commentary:
+;; Convenience functions to report about the host environment
+
+;;; Code:
+
+(require 'battery)
+
+(defun env-laptop-p ()
+ "Return t if host is a laptop (has a battery), nil if not."
+ (when (and battery-status-function
+ (not (string-match-p "N/A"
+ (battery-format "%B"
+ (funcall battery-status-function)))))
+ t))
+
+(defun env-desktop-p ()
+ "Return t if host is a laptop (has a battery), nil if not."
+ (when (not (env-laptop-p))
+ t))
+
+(defun env-linux-p ()
+ "Return t if host system is GNU/Linux."
+ (string-equal system-type "gnu/linux"))
+
+(defun env-bsd-p ()
+ "Return t if host system is FreeBSD."
+ (string-equal system-type "berkeley-unix"))
+
+(defun env-macos-p ()
+ "Return t if host system is Mac OS (darwin-based)."
+ (string-equal system-type "darwin"))
+
+(defun env-windows-p ()
+ "Return t if host system is Windows."
+ (memq system-type '(cygwin windows-nt ms-dos)))
+
+(defun env-terminal-p ()
+ "Return t if running in a terminal."
+ (not (display-graphic-p)))
+
+(defun env-gui-p ()
+ "Return t if running in graphical environment."
+ (display-graphic-p))
+
+(provide 'host-environment)
+;;; host-environment.el ends here.