instow

:)
git clone https://git.sr.ht/~ashymad/instow
Log | Files | Refs | LICENSE

commit 71513e09a6010045ac3b0c0f1bf6b625a6069e3b
parent d98c8d83ba3da17fcc854b9d3d49d9f31b2ec612
Author: Ashymad <szymon.mikulicz@posteo.net>
Date:   Tue, 24 Feb 2026 23:41:30 +0100

More janet

Diffstat:
Minstowl.janet | 23++++++++++++++---------
1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/instowl.janet b/instowl.janet @@ -1,6 +1,7 @@ #!/usr/bin/env janet -(import jpm/shutil) +(import spork/sh) +(import spork/path) (ffi/context nil) (ffi/defbind mkdtemp :ptr [template :ptr]) @@ -17,7 +18,7 @@ (defn file-exists? [path] (not (nil? (os/stat path)))) -(defn prinfer [state pipe] +(defn prinfer [state logfile pipe] (do (def buf @"") (while (ev/read pipe 1024 buf) @@ -27,6 +28,7 @@ (loop [[idx line] :pairs lines] (if (< idx (- len 1)) (do + (file/write logfile line "\n") (prinf "\x1b[2K{%s}⸉%s⸊→%s\r" state ch (string/slice line 0 (min 80 (length line)))) (flush)) (do (buffer/clear buf) (buffer/push-string buf line)))))))) @@ -34,9 +36,10 @@ (defn runp [state & args] (def proc (os/spawn args : {:out :pipe :err :pipe})) + (def logfile (file/open "./instowl.log" :a)) (ev/gather - (prinfer state (proc :out)) - (prinfer state (proc :err)) + (prinfer state logfile (proc :out)) + (prinfer state logfile (proc :err)) (os/proc-wait proc) (while (= (get proc :return-code) nil) (ev/sleep 0.2) (do (set ch (rotate ch)) @@ -44,6 +47,7 @@ (flush)))) (def code (get proc :return-code)) (os/proc-close proc) + (file/close logfile) code) (defn main @@ -51,8 +55,8 @@ (do (def target (string/join [(os/getenv "HOME") "/.local"])) (def stowdir (string/join [target "/pkg"])) - (def pkg (shutil/basename (os/getenv "PWD"))) - (def pkgdir (string/join [stowdir pkg])) + (def pkg (path/basename (os/getenv "PWD"))) + (def pkgdir (string/join [stowdir "/" pkg ])) (def destdir @"/tmp/instowl.XXXXXX") (var prefix target) @@ -64,8 +68,9 @@ :conf/autotools (if (= (runp state "/usr/bin/autoreconf" "-vi") 0) (set state :conf/configure) (set state :error)) :conf/configure (if (= (runp state "./configure" "--prefix" prefix) 0) (set state :build/make) (set state :error)) :build/make (if (= (runp state "/usr/bin/make") 0) (set state :install/pre) (set state :error)) - :install/pre (do (shutil/create-dirs pkgdir) (mkdtemp destdir) (set state :install/make)) - :install/make (if (= (runp state "/usr/bin/make" "install" (string/format "-j%d" (get_nprocs)) (string/join ["DESTDIR=" destdir])) 0) (set state :install/post)) - :install/post (set state :done) + :install/pre (do (sh/create-dirs pkgdir) (mkdtemp destdir) (set state :install/make)) + :install/make (if (= (runp state "/usr/bin/make" "install" (string/format "-j%d" (get_nprocs)) (string/join ["DESTDIR=" destdir])) 0) (set state :install/post) (set state :error)) + :install/post (do (def installdir (string/join [destdir prefix])) (loop [file :in (sh/list-all-files installdir)] (sh/copy-file file (string/replace installdir pkgdir file))) (set state :stow)) + :stow (if (= (runp state "/usr/bin/xstow" "-v" "-d" stowdir "-t" target pkg) 0) (set state :done) (set state :error)) :error (do (printf "\x1b[2K⸉!⸊→Error") (set state :exit)) :done (do (printf "\x1b[2K⸉x⸊→Done") (set state :exit))))))