blob: 91839d8e5318501c29f2612e28bdbd2e38a9d804 (
about) (
plain)
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
|
#!/usr/bin/env -S guile --no-auto-compile
!#
(use-modules (ice-9 format)
(ice-9 match)
(ice-9 ports))
(define (call-command/stderr . command)
"Call COMMAND using `system*', but redirect all output to stderr."
(with-output-to-port (current-error-port)
(lambda () (apply system* command))))
(match (command-line)
((_ "quit")
(exit 0))
((_ "Reload i3 configuration")
(call-command/stderr "i3-msg" "reload"))
((_ "Sleep")
;; "screenlock" blocks until unlocked by the user, so run in background.
;; TODO: write "mem" to /sys/power/state, but it's owned by root.
(let ((locker (spawn "screenlock" '("screenlock")))
(sleepfile (open-file "/sys/power/state" "w")))
(display "mem" sleepfile)
(close sleepfile)
(waitpid locker)))
((_ "Log out")
(call-command/stderr "i3-msg" "exit"))
((_ "Shutdown")
(call-command/stderr "sudo" "-n" "/run/current-system/profile/sbin/shutdown"))
((_ "Reboot")
(call-command/stderr "sudo" "-n" "/run/current-system/profile/sbin/reboot"))
(_
(format #t "\0~a\x1f~a~%~{~a\0icon\x1f~a~%~}"
"prompt" "Session"
'("Reload i3 configuration" "reload"
"Sleep" "system-suspend"
"Log out" "system-log-out"
"Shutdown" "system-shutdown"
"Reboot" "system-reboot"))))
|