about summary refs log tree commit diff
path: root/init/nixos.el
blob: ab62f81909dfa48d86d5c8d544149b36f17355c6 (plain) (blame)
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
53
54
55
56
57
;; Configure additional settings if this is one of my NixOS machines
;; (i.e. if ExWM is required)
;; -*- lexical-binding: t; -*-

(require 's)
(require 'f)

(defvar is-nixos
  (let ((os-f "/etc/os-release"))
    (s-contains?
     "NixOS" (if (f-file? os-f) (f-read os-f)))))

(if is-nixos
    (progn
      (message "Running on NixOS, configuring ExWM.")
      (require 'exwm)
      (require 'exwm-config)

      ;; Start with one workspace (make more as needed)
      (setq exwm-workspace-number 1)
      ;; Make class name the buffer name
      (add-hook 'exwm-update-class-hook
                (lambda ()
                  (exwm-workspace-rename-buffer exwm-class-name)))

      ;; 's-r': Reset
      (exwm-input-set-key (kbd "s-r") #'exwm-reset)
      ;; 's-w': Switch workspace
      (exwm-input-set-key (kbd "s-w") #'exwm-workspace-switch)
      ;; 's-N': Switch to certain workspace
      (dotimes (i 10)
        (exwm-input-set-key (kbd (format "s-%d" i))
                            `(lambda ()
                               (interactive)
                               (exwm-workspace-switch-create ,i))))

      ;; Launch applications with completion (dmenu style!)
      (exwm-input-set-key (kbd "s-p") #'helm-run-external-command)

      ;; Line-editing shortcuts
      (exwm-input-set-simulation-keys
       '(([?\C-b] . left)
         ([?\C-f] . right)
         ([?\C-p] . up)
         ([?\C-n] . down)
         ([?\C-a] . home)
         ([?\C-e] . end)
         ([?\M-v] . prior)
         ([?\C-v] . next)
         ([?\C-d] . delete)
         ([?\C-k] . (S-end delete))))

      ;; Enable EXWM
      (exwm-enable)
      (fringe-mode 1)))

(provide 'nixos)