-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathkeybindings.lisp
141 lines (106 loc) · 4.81 KB
/
keybindings.lisp
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
(in-package :stumpwm)
;; Double check prefix-key is set correctly
(set-prefix-key (kbd "C-t"))
;; Emacs Style Frame Splitting
(define-key *root-map* (kbd "0") "remove")
(define-key *root-map* (kbd "1") "only")
(define-key *root-map* (kbd "2") "vsplit")
(define-key *root-map* (kbd "3") "hsplit")
(defmacro make-program-binding (program-name window-class &optional alias)
"Create run-or-raise and run-or-pull commands for program-name
window-class is the windows-class
Also add keybinding to the commands.
C-keybinding r calls run-or-raise
C-keybinding p calls run-or-pull
C-keybinding n creates a new instance of the program"
(if (not alias)
(setf alias program-name))
`(progn
(defvar ,(intern (format nil "*~a-map*" alias)) nil)
(defcommand ,(intern (format nil "~a" alias)) () () (run-shell-command ,program-name))
(defcommand ,(intern (format nil "run-or-raise-~a" alias)) () ()
(run-or-raise ,program-name '(:class ,window-class)))
(defcommand ,(intern (format nil "run-or-pull-~a" alias)) () ()
(run-or-pull ,program-name '(:class ,window-class)))
(fill-keymap ,(intern (format nil "*~a-map*" alias))
(kbd "p") ,(format nil "run-or-pull-~a" alias)
(kbd "r") ,(format nil "run-or-raise-~a" alias)
(kbd "n") ,(format nil "~a" alias))))
(make-program-binding "firefox-developer-edition" "firefoxdeveloperedition" "firefox")
(make-program-binding "thunar" "Thunar")
(make-program-binding "slack" "Slack")
(make-program-binding "alacritty" "Alacritty")
(make-program-binding "emacs" "Emacs" "emacs")
(make-program-binding "insomnia" "Insomnia")
(make-program-binding "keepassxc" "KeePassXC")
(make-program-binding "google-chrome-stable" "Google-chrome" "chrome")
(make-program-binding "mongodb-compass" "mongodb-compass")
(make-program-binding "dbeaver" "DBeaver")
(make-program-binding "spotify" "Spotify")
(make-program-binding "keepassxc" "keepassxc")
(defparameter *program-map*
(let ((m (make-sparse-keymap)))
(define-key m (kbd "f") |*firefox-map*|)
(define-key m (kbd "s") |*slack-map*|)
(define-key m (kbd "e") |*emacs-map*|)
(define-key m (kbd "m") |*thunar-map*|)
(define-key m (kbd "c") |*alacritty-map*|)
(define-key m (kbd "q") |*spotify-map*|)
(define-key m (kbd "p") |*keepassxc-map*|)
(define-key m (kbd "g") |*chrome-map*|)
m))
(define-key *root-map* (kbd "p") *program-map*)
;; Setup bindings for less common aplications which would be opened then closed
(defcommand screenshot () ()
"Do we wanna Scrot? Yeah! We wanna Scrot!"
(run-shell-command "cd /home/thomas/Pictures/screenshots/; scrot"))
(defcommand screenshot-name () ()
"Do we wanna Scrot? Yeah! We wanna Scrot!"
(let ((filename (read-one-line (current-screen) "Filename:")))
(run-shell-command (concat "cd /home/thomas/Pictures/screenshots/; scrot " filename ".png") t)))
(defcommand screenshot-select () ()
"Do we wanna Scrot? Yeah! We wanna Scrot!"
(run-shell-command "cd /home/thomas/Pictures/screenshots/; scrot -s"))
(defcommand screenshot-name-select () ()
"Do we wanna Scrot? Yeah! We wanna Scrot!"
(let ((filename (read-one-line (current-screen) "Filename:")))
(run-shell-command (concat "cd /home/thomas/Pictures/screenshots/; scrot -s " filename ".png") t)))
(defcommand volume-control () ()
"Start volume control"
(run-or-raise "pavucontrol" '(:class "Pavucontrol")))
;;; Shutdown and Reboot
(defcommand shutdown (confirm) ((:y-or-n "Confirm Shutdown "))
"Ask for the user to confirm before shutting down."
(if confirm
(run-shell-command "poweroff")))
(defcommand reboot (confirm) ((:y-or-n "Confirm Reboot "))
"Ask for the user to confirm before rebooting."
(if confirm
(run-shell-command "reboot")))
;;; System Command Keymap
(defparameter *screenshot-map*
(let ((m (make-sparse-keymap)))
(define-key m (kbd "f") "screenshot")
(define-key m (kbd "n") "screenshot-name")
(define-key m (kbd "s") "screenshot-select")
m))
(defparameter *power-map*
(let ((m (make-sparse-keymap)))
(define-key m (kbd "p") "shutdown")
(define-key m (kbd "r") "reboot")
m))
(defparameter *system-map*
(let ((m (make-sparse-keymap)))
(define-key m (kbd "s") *screenshot-map*)
(define-key m (kbd "p") *power-map*)
(define-key m (kbd "v") "volume-control")
m))
(define-key *root-map* (kbd "s") *system-map*)
(defcommand user-switch-to-screen (screen-num) ((:number "Screen Number: "))
"Only works when there is a currently open window on the screen"
(select-window-by-number (window-number (car (head-windows (current-group)
(nth screen-num (group-heads (current-group)))))))
(group-wake-up (current-group)))
(define-key *root-map* (kbd "F1") "user-switch-to-screen 2")
(define-key *root-map* (kbd "F2") "user-switch-to-screen 1")
(define-key *root-map* (kbd "F3") "user-switch-to-screen 0")