My emacs now behaves differently when I’m at home! This enables me to have my private configuration loaded automatically when needed, while I have all my work-settings enabled otherwise.
Emacs’ org-mode is a tool I use almost daily for my note-taking. I don’t attempt to capture everything in emacs, but most of my notes eventually end up either there or in one of my physical notebooks. In emacs, I use different notebooks depending on whether I’m at work or not. With the following snippet in my config, the information on the kind of environment is set as the environment variable SYSENV:
(message "Updating the SYSENV based on the connected wifi...")
(setq home-wifi "FRITZ!Box 7530 RG\n")
(if (string-equal home-wifi (shell-command-to-string "nmcli -g NAME connection show --active"))
(setenv "SYSENV" "home"))
I then make use of that information in other places, for example for my shortcut to open my notebook:
(defun fbr/open_main_agenda_file()
(interactive)
(case (intern (getenv "SYSENV"))
(home (find-file "~/Dropbox/org/gtd/tasks.org"))
(work (find-file "~/Documents/org/projects.org"))
(otherwise (message "No SYSENV found. Don't know what to open."))
)
)
(define-key global-map (kbd "<f6>") 'fbr/open_main_agenda_file)
The SYSENV environment variable configuration is an idea I borrowed from some other config. It allows me to set this configuration outside of my emacs, for example in the .bashrc. This helped me out in the past, and allowed me have the same configuration running on a windows home PC, a debian study laptop and a redhat work laptop. Configuration that only worked with a certain OS or was only needed for example for studying could be loaded conditionally and reliably.
These days I only have a single OS I’m working with and even only a single piece of hardware. In the .bashrc the SYSENV is therefor set to work as a default and conditionally overwritten based on the connected WIFI. Even though the amount of environments has now decreased, the SYSENV is still helping me out with my purpose-dependant org-mode configuration.
I hope you found this small snippet useful or inspiring, as it shows how easy it is to make your emacs smarter.