guile-swayer/commander

38 lines
1.2 KiB
Text
Raw Normal View History

2024-06-15 09:57:11 +02:00
#!/usr/bin/guile \
-e main -s
!#
;; #!/usr/bin/guile --fresh-auto-compile
;; ensure that the swayipc module is available under the same directory as the init file
;; otherwise, the module should be referenced from packaging system or via custom load path
(add-to-load-path
(dirname (or (current-filename)
(string-append (getenv "HOME") "/.config/sway/init.scm"))))
(use-modules (swayipc connection)
(ice-9 popen)
(sjson builder)
(ice-9 binary-ports)
(rnrs bytevectors)
(rnrs io ports)
(oop goops)
(srfi srfi-18)
(srfi srfi-9)
(srfi srfi-1))
(define COMMANDS-CLIENT-SOCKET (socket AF_UNIX SOCK_STREAM 0))
2024-06-18 18:05:39 +02:00
(format #t "connecting to ~a\n" SOCKET-COMMANDS-LISTENER-PATH)
2024-06-15 09:57:11 +02:00
(connect COMMANDS-CLIENT-SOCKET
(make-socket-address AF_UNIX SOCKET-COMMANDS-LISTENER-PATH))
(display "connected\n")
(define (send-command command)
2024-06-18 18:05:39 +02:00
(format #t "sending command: ~a\n" command)
2024-06-15 09:57:11 +02:00
(display (write-msg COMMANDS-CLIENT-SOCKET
RUN-COMMMAND-MSG-ID
(scm->json-string command)))
(display "sent\n"))
(define (main args)
(send-command (string-join (cdr args) " ")))