-
Notifications
You must be signed in to change notification settings - Fork 0
/
rofi.lisp
54 lines (45 loc) · 1.86 KB
/
rofi.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
(in-package :rofi)
(defun escape-item-name (var)
(substitute #\MODIFIER_LETTER_DOUBLE_PRIME #\" var))
(defun prepare-items (items)
(format nil "~{~A~^~%~}" (mapcar #'car items)))
(defun run (items &optional (args ""))
(uiop:run-program (format nil "echo \"~A\" | rofi -dmenu ~A"
(escape-item-name (prepare-items items))
args)
:ignore-error-status t
:error-output '(:string :stripped t)
:output '(:string :stripped t)))
(defun choose (items args)
(multiple-value-bind (out-text err-text err-code)
(run items args)
(declare (ignore err-text))
(when (eq err-code 0)
(assoc out-text items
:test #'(lambda (chosen-text item-name)
(string= chosen-text (escape-item-name item-name)))))))
(defun menu (items &optional (args ""))
(when-let ((item-val (cdr (choose items args))))
(if (stringp item-val)
(run-commands item-val)
(progn
(sleep 0.1)
(menu item-val args)))))
(defun window-name (window)
(format nil "~A (~A)"
(stumpwm::window-class window)
(stumpwm::window-name window)))
(defcommand rofi-colon () ()
(let ((commands (mapcar #'list
(stumpwm::all-commands))))
(when-let ((cmd (car (choose commands ""))))
(run-commands cmd))))
(defcommand rofi-windowlist (&optional window-list) (:rest)
(if-let ((window-list (mapcar (lambda (w) (cons (window-name w) w))
(or window-list
(stumpwm::sort-windows-by-number
(group-windows (current-group)))))))
(if-let ((window (cdr (choose window-list ""))))
(group-focus-window (current-group) window)
(throw 'error :abort))
(message "No Managed Windows")))