emacs - system type
Table of Contents
How to determine operating system in elisp?
https://stackoverflow.com/questions/1817257/how-to-determine-operating-system-in-elisp
The system-type variable:
system-type is a variable defined in C source code.
Documentation: Value is symbol indicating type of operating system you are using.
Special values:
gnucompiled for a GNU Hurd system.gnu/linuxcompiled for a GNU/Linux system.darwincompiled for Darwin (GNU-Darwin, Mac OS X, …).ms-doscompiled as an MS-DOS application.windows-ntcompiled as a native W32 application.cygwincompiled using the Cygwin library.
Anything else indicates some sort of Unix system.
Conditional logic in .el files
For folks newer to elisp, a sample usage:
(if (eq system-type 'darwin)
; something for OS X if true
; optional something if not
)
Or, if we don’t care for the else-form and have multiple then-forms,
(when (eq system-type 'darwin)
; do this
; and this ...
)
How to determine the system-type of your computer?
Paste it in your scratch buffer and press C-j after the outermost parenthesis.
(pcase system-type
;; GNU/Linux or WSL
(gnu/linux
(message "This is GNU/Linux"))
;; macOS
(darwin
(message "This is macOS"))
;; Windows
(windows-nt
(message "This is Windows"))
;; BSDs
(berkeley-unix
(message "This is a BSD"))
;; Other operating system
(_
(message "Unknown operating system")))