-
-
Save borkdude/82dcdd36a1e61ef36f19221876e7b1b6 to your computer and use it in GitHub Desktop.
vipe for babashka - see https://github.com/juliangruber/vipe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# temp file | |
t=/tmp/bipe.$$.txt | |
touch $t | |
# read from stdin | |
if [ ! -t 0 ]; then | |
cat > $t | |
fi | |
# spawn babashka with stdio connected | |
rlwrap bb -e " | |
(def stdin (slurp \"$t\")) | |
(def res (atom stdin)) | |
(.addShutdownHook (.getRuntime Runtime) | |
(Thread. (fn [] (spit \"$t\" @res)))) | |
(binding [*1 *1 | |
*2 *2 | |
*3 *3] | |
(clojure.main/repl | |
:init (fn [] (println \"Evaluate 'stdin' to see piped input.\") | |
(println \"The last return value is piped to the next command.\") | |
(println \"Use :repl/quit to quit the REPL.\")) | |
:eval (fn [x] (let [x (eval x)] | |
(reset! res x) | |
;; this should not be part of the eval function and should be fixed in bb's clojure.main/repl | |
;; similar for *e | |
(set! *3 *2) | |
(set! *2 *1) | |
(set! *1 x) | |
x)))) | |
(spit \"$t\" @res) | |
" < /dev/tty > /dev/tty || exit $? | |
# write to stdout | |
cat $t | |
# cleanup | |
rm $t |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example usage: