#!/usr/bin/env -S guile --no-auto-compile !# (use-modules (ice-9 format) (ice-9 match) (ice-9 ports)) (define wm (cond ((getenv "SWAYSOCK") 'sway) ((getenv "I3SOCK") 'i3) (else #f))) (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)))) (define (wm-msg . command) (apply call-command/stderr (match wm (sway "swaymsg") (i3 "i3-msg") (_ (error "No recognised window manager running"))) command)) (match (command-line) ((_ "quit") (exit 0)) ((_ "Reload WM configuration") (wm-msg "reload")) ((_ "Sleep") ;; Rely on swayidle to lock the screen before going to sleep. (call-command/stderr "loginctl" "suspend")) ((_ "Log out") (wm-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" `(,@(if wm '("Reload WM configuration" "reload" "Log out" "system-log-out") '()) "Sleep" "system-suspend" "Shutdown" "system-shutdown" "Reboot" "system-reboot"))))