guile-swayer/commander
2024-06-18 19:05:39 +03:00

37 lines
1.2 KiB
Scheme
Executable file

#!/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))
(format #t "connecting to ~a\n" SOCKET-COMMANDS-LISTENER-PATH)
(connect COMMANDS-CLIENT-SOCKET
(make-socket-address AF_UNIX SOCKET-COMMANDS-LISTENER-PATH))
(display "connected\n")
(define (send-command command)
(format #t "sending command: ~a\n" command)
(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) " ")))