From 9ecfc9585107f43a91cd6da3ba1c0598a2960797 Mon Sep 17 00:00:00 2001 From: BardofSprites <89086143+BardofSprites@users.noreply.github.com> Date: Mon, 2 Feb 2026 19:03:53 -0500 Subject: new scheme scripts --- bin/.local/bin/scripts/lisp/dmenu.scm | 44 ++++++++++++++++++++++++++++++++++ bin/.local/bin/scripts/lisp/wacom.scm | 29 ++++++++++++++++++++++ bin/.local/bin/scripts/lisp/xrandr.scm | 14 +++++++++++ 3 files changed, 87 insertions(+) create mode 100644 bin/.local/bin/scripts/lisp/dmenu.scm create mode 100755 bin/.local/bin/scripts/lisp/wacom.scm create mode 100644 bin/.local/bin/scripts/lisp/xrandr.scm (limited to 'bin') 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)) -- cgit v1.2.3