aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBardofSprites <[email protected]>2026-02-02 19:03:53 -0500
committerBardofSprites <[email protected]>2026-02-02 19:03:53 -0500
commit9ecfc9585107f43a91cd6da3ba1c0598a2960797 (patch)
treea7106b092804fc2ee0c067c909e25df659e347e4
parent3ea9b0af92fdcbeefe101c3731d200a421a74575 (diff)
new scheme scripts
-rw-r--r--bin/.local/bin/scripts/lisp/dmenu.scm44
-rwxr-xr-xbin/.local/bin/scripts/lisp/wacom.scm29
-rw-r--r--bin/.local/bin/scripts/lisp/xrandr.scm14
3 files changed, 87 insertions, 0 deletions
diff --git a/bin/.local/bin/scripts/lisp/dmenu.scm b/bin/.local/bin/scripts/lisp/dmenu.scm
new file mode 100644
index 0000000..5e838d9
--- /dev/null
+++ b/bin/.local/bin/scripts/lisp/dmenu.scm
@@ -0,0 +1,44 @@
+(define (dmenu-prompt options :optional (prompt "Prompt:"))
+ (let* ((dmenu-cmd '("dmenu" "-p"))
+ (full-cmd (append dmenu-cmd (list prompt)))
+ (process (run-process full-cmd
+ :input :pipe ; Pipe stdin to dmenu
+ :output :pipe ; Capture dmenu's stdout
+ :error :inherit
+ :wait #f))
+ (input-port (process-input process))
+ (output-port (process-output process)))
+
+ ;; Write the options to dmenu's stdin
+ (for-each (lambda (item) (format input-port "~a~%" item)) options)
+ (close-output-port input-port)
+
+ ;; Read the selected line
+ (let ((selection (read-line output-port)))
+ (process-wait process)
+ (close-input-port output-port)
+
+ (if (eof-object? selection)
+ #f
+ selection))))
+
+(define (prompt-dispatch options :optional (title "Select:"))
+ ;; Options must be in quasi quoted list
+ ;; Example:
+ ;; (prompt-dispatch
+ ;; `(("action1" . "return string")
+ ;; ("action2" . ,(exectute-function "arguments"))
+ ;; ("action3" . (run-a-command "with arguments"))))
+ (let* ((labels (map car options))
+ (choice (dmenu-prompt labels title))
+ (entry (assoc choice options)))
+ (and entry
+ (let ((action (cdr entry)))
+ (cond
+ ((procedure? action) ;; eval if function ,(function args)
+ (action))
+ ((list? action) ;; regular list becomes process (command "args")
+ (run-process action))
+ ((string? action) ;; return string
+ action)
+ (else action))))))
diff --git a/bin/.local/bin/scripts/lisp/wacom.scm b/bin/.local/bin/scripts/lisp/wacom.scm
new file mode 100755
index 0000000..053fe19
--- /dev/null
+++ b/bin/.local/bin/scripts/lisp/wacom.scm
@@ -0,0 +1,29 @@
+#!/usr/bin/env gosh
+
+(use gauche.process)
+(use srfi-1)
+
+(load "~/.local/bin/scripts/lisp/dmenu.scm")
+
+(define (find-id)
+ (let ((out (process-output->string '(xsetwacom --list devices))))
+ (let loop ((lines (string-split out #\newline)))
+ (cond
+ ((null? lines) #f)
+ ((rxmatch #/^Wacom.*STYLUS.*id:\s*(\d+)/i (car lines))
+ => (lambda (m) (rxmatch-substring m 1)))
+ (else (loop (cdr lines)))))))
+
+(define (monitor-prompt)
+ (prompt-dispatch
+ `(("Main" . "1920x1080+0+0")
+ ("Side" . "1920x1080+1920+0")
+ ("Desktop" . "desktop"))
+ "Monitor range: "))
+
+(define (set-range)
+ (let* ((range (monitor-prompt))
+ (id (find-id)))
+ (run-process (list "xsetwacom" "set" id "MapToOutput" range))))
+
+(set-range)
diff --git a/bin/.local/bin/scripts/lisp/xrandr.scm b/bin/.local/bin/scripts/lisp/xrandr.scm
new file mode 100644
index 0000000..a935fab
--- /dev/null
+++ b/bin/.local/bin/scripts/lisp/xrandr.scm
@@ -0,0 +1,14 @@
+(use gauche.process)
+(use srfi-1) ;; string splitting
+
+(define (xrandr-connected-outputs)
+ (let* ((lines (process-output->string-list '("xrandr" "--query") :error :exit-code))
+ (outputs
+ (filter-map
+ (lambda (line)
+ (let ((words (string-split line #\space)))
+ (and (>= (length words) 2)
+ (string=? (list-ref words 1) "connected")
+ (list-ref words 0))))
+ lines)))
+ outputs))