(define-module (bs shell) #:use-module ((ice-9 popen) #:prefix popen/) #:use-module ((ice-9 rdelim) #:prefix rdelim/) #:use-module ((ice-9 ftw) #:prefix ftw/) #:export (exec stream pwd ls cd)) (define (exec cmd) (let* ((port (popen/open-input-pipe cmd)) (ret (rdelim/read-string port))) (popen/close-pipe port) ret)) (define (stream cmd) (let* ((port (popen/open-input-pipe cmd)) (_ (setvbuf port 'none)) (ret (rdelim/read-string port))) (flush-all-ports) (popen/close-pipe port) ret)) (define pwd getcwd) (define (ls) (ftw/scandir (getcwd))) (define (cd path) (chdir path) (ls)) ;; run shell commands with #$"cmd args" ;; #$"who" ;; ben tty7 2022-11-07 20:31 (:0) (read-hash-extend #\$ (lambda (c port) (let ((input (read port))) ;; todo: ;; - parse input for #{interpolations} ;; - evaluate scheme code inside the blocks ;; - then exec this `(exec ,input))))