bash: Disallow overwriting existing file using shell redirection
[~bandali/configs] / .emacs.d / lisp / bandali-exwm.el
1 ;;; bandali-exwm.el --- bandali's EXWM configuration -*- lexical-binding: t; -*-
2
3 ;; Copyright (C) 2018-2020 Amin Bandali
4
5 ;; Author: Amin Bandali <bandali@gnu.org>
6 ;; Keywords: tools
7
8 ;; This program is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation, either version 3 of the License, or
11 ;; (at your option) any later version.
12
13 ;; This program is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
17
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with this program. If not, see <https://www.gnu.org/licenses/>.
20
21 ;;; Commentary:
22
23 ;; My EXWM setup. Makes good use of its simulation keys.
24
25 ;;; Code:
26
27 (add-to-list 'load-path (b/lisp "xelb"))
28 (add-to-list 'load-path (b/lisp "exwm"))
29 (require 'exwm)
30 ;; make class name the buffer name, truncating beyond 60 characters
31 (defun b/exwm-rename-buffer ()
32 (interactive)
33 (exwm-workspace-rename-buffer
34 (concat exwm-class-name ":"
35 (if (<= (length exwm-title) 60) exwm-title
36 (concat (substring exwm-title 0 59) "...")))))
37 ;; Enable EXWM
38 (exwm-enable)
39 (add-hook 'exwm-update-class-hook #'b/exwm-rename-buffer)
40 (add-hook 'exwm-update-title-hook #'b/exwm-rename-buffer)
41
42 (require 'exwm-config)
43 (add-hook 'exwm-init-hook #'exwm-config--fix/ido-buffer-window-other-frame)
44
45 (require 'exwm-input)
46 (defun b/exwm-ws-prev-index ()
47 "Return the index for the previous EXWM workspace, wrapping
48 around if needed."
49 (if (= exwm-workspace-current-index 0)
50 (1- exwm-workspace-number)
51 (1- exwm-workspace-current-index)))
52
53 (defun b/exwm-ws-next-index ()
54 "Return the index for the next EXWM workspace, wrapping
55 around if needed."
56 (if (= exwm-workspace-current-index
57 (1- exwm-workspace-number))
58 0
59 (1+ exwm-workspace-current-index)))
60
61 ;; shorten 'C-c C-q' to 'C-q'
62 (define-key exwm-mode-map [?\C-q] #'exwm-input-send-next-key)
63
64 (csetq exwm-workspace-number 4
65 exwm-input-global-keys
66 `(([?\s-R] . exwm-reset)
67 ([?\s-\\] . exwm-workspace-switch)
68 ([?\s-\s] . dmenu)
69 ([?\S-\s-\s] . (lambda (command)
70 (interactive
71 (list (read-shell-command "➜ ")))
72 (start-process-shell-command
73 command nil command)))
74 ([s-return] . (lambda ()
75 (interactive)
76 (start-process "" nil "urxvt")))
77 ([?\C-\s-\s] . counsel-linux-app)
78 ([?\M-\s-\s] . (lambda ()
79 (interactive)
80 (start-process-shell-command
81 "rofi-pass" nil "rofi-pass")))
82 ([?\s-h] . windmove-left)
83 ([?\s-j] . windmove-down)
84 ([?\s-k] . windmove-up)
85 ([?\s-l] . windmove-right)
86 ([?\s-H] . windmove-swap-states-left)
87 ([?\s-J] . windmove-swap-states-down)
88 ([?\s-K] . windmove-swap-states-up)
89 ([?\s-L] . windmove-swap-states-right)
90 ([?\M-\s-h] . shrink-window-horizontally)
91 ([?\M-\s-l] . enlarge-window-horizontally)
92 ([?\M-\s-k] . shrink-window)
93 ([?\M-\s-j] . enlarge-window)
94 ([?\s-\[] . (lambda ()
95 (interactive)
96 (exwm-workspace-switch-create
97 (b/exwm-ws-prev-index))))
98 ([?\s-\]] . (lambda ()
99 (interactive)
100 (exwm-workspace-switch-create
101 (b/exwm-ws-next-index))))
102 ([?\s-{] . (lambda ()
103 (interactive)
104 (exwm-workspace-move-window
105 (b/exwm-ws-prev-index))))
106 ([?\s-}] . (lambda ()
107 (interactive)
108 (exwm-workspace-move-window
109 (b/exwm-ws-next-index))))
110 ,@(mapcar (lambda (i)
111 `(,(kbd (format "s-%d" i)) .
112 (lambda ()
113 (interactive)
114 (exwm-workspace-switch-create ,i))))
115 (number-sequence 0 (1- exwm-workspace-number)))
116 ([?\s-t] . exwm-floating-toggle-floating)
117 ([?\s-f] . exwm-layout-toggle-fullscreen)
118 ([?\s-W] . (lambda ()
119 (interactive)
120 (kill-buffer (current-buffer))))
121 ([?\s-Q] . (lambda ()
122 (interactive)
123 (exwm-manage--kill-client)))
124 ([?\s-\'] . (lambda ()
125 (interactive)
126 (start-process-shell-command
127 "rofi-light" nil "rofi-light")))
128 ([XF86AudioMute] .
129 (lambda ()
130 (interactive)
131 (start-process "" nil "amixer" "set" "'Master',0" "toggle")))
132 ([XF86AudioLowerVolume] .
133 (lambda ()
134 (interactive)
135 (start-process
136 "" nil "amixer" "set" "'Master',0" "5%-")))
137 ([XF86AudioRaiseVolume] .
138 (lambda ()
139 (interactive)
140 (start-process
141 "" nil "amixer" "set" "'Master',0" "5%+")))
142 ([XF86AudioPlay] .
143 (lambda ()
144 (interactive)
145 (start-process "" nil "mpc" "toggle")))
146 ([XF86AudioPrev] .
147 (lambda ()
148 (interactive)
149 (start-process "" nil "mpc" "prev")))
150 ([XF86AudioNext] .
151 (lambda ()
152 (interactive)
153 (start-process "" nil "mpc" "next")))
154 ([XF86ScreenSaver] .
155 (lambda ()
156 (interactive)
157 (start-process "" nil "dm-tool" "lock")))
158 ([\s-XF86Back] . previous-buffer)
159 ([\s-XF86Forward] . next-buffer)))
160
161 ;; Line-editing shortcuts
162 (csetq exwm-input-simulation-keys
163 '(;; movement
164 ([?\C-b] . [left])
165 ([?\M-b] . [C-left])
166 ([?\C-f] . [right])
167 ([?\M-f] . [C-right])
168 ([?\C-p] . [up])
169 ([?\C-n] . [down])
170 ([?\C-a] . [home])
171 ([?\C-e] . [end])
172 ([?\M-v] . [prior])
173 ([?\C-v] . [next])
174 ([?\C-d] . [delete])
175 ([?\C-k] . [S-end ?\C-x])
176 ([?\M-<] . C-home)
177 ([?\M->] . C-end)
178 ;; cut/copy/paste
179 ([?\C-w] . [?\C-x])
180 ([?\M-w] . [?\C-c])
181 ([?\C-y] . [?\C-v])
182 ([?\M-d] . [C-S-right ?\C-x])
183 ([?\M-\d] . [C-S-left ?\C-x])
184 ;; window
185 ([?\s-w] . [?\C-w])
186 ([?\s-q] . [?\C-q])
187 ;; misc
188 ([?\C-s] . [?\C-f])
189 ([?\s-s] . [?\C-s])
190 ([?\C-g] . [escape])))
191
192 (require 'exwm-manage)
193 (add-hook 'exwm-manage-finish-hook
194 (lambda ()
195 (when exwm-class-name
196 (cond
197 ((string= exwm-class-name "IceCat")
198 (exwm-input-set-local-simulation-keys
199 `(,@exwm-input-simulation-keys
200 ([?\C-\S-d] . [?\C-d]))))
201 ((string= exwm-class-name "URxvt")
202 (exwm-input-set-local-simulation-keys
203 '(([?\C-c ?\C-c] . [?\C-c])
204 ([?\C-c ?\C-u] . [?\C-u]))))
205 ((string= exwm-class-name "Zathura")
206 (exwm-input-set-local-simulation-keys
207 '(([?\C-p] . [C-up])
208 ([?\C-n] . [C-down]))))))))
209
210 (require 'exwm-randr)
211 (exwm-randr-enable)
212 (csetq exwm-randr-workspace-monitor-plist '(1 "VGA-1"))
213
214 (require 'exwm-systemtray)
215 (exwm-systemtray-enable)
216
217 (add-to-list 'load-path (b/lisp "exwm-edit"))
218 (require 'exwm-edit)
219
220 (provide 'bandali-exwm)
221 ;;; bandali-exwm.el ends here