summaryrefslogtreecommitdiff
path: root/modules/host-environment.el
blob: 20986b1a9053b235e1492ea184af3d9b413d3efd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
;;; 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 (i.e., 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-x-p ()
  "Return t if host system is running the X Window System"
  (string= (window-system) "x"))

(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.