Last active
May 27, 2022 14:26
-
-
Save borkdude/d7e5647d77b27a664bd6135e68cccbaf to your computer and use it in GitHub Desktop.
Fun (non-serious) small shell in babashka
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 rlwrap bb | |
(ns bbsh | |
(:require | |
[babashka.fs :as fs] | |
[babashka.process :as process] | |
[clojure.string :as str])) | |
(defmacro % [& args] | |
`(do @(process/$ {:inherit true} ~@args) | |
nil)) | |
(defn next-line [] | |
(print (str *ns* "> ")) | |
(flush) | |
(read-line)) | |
(defn run-shell [] | |
(loop [] | |
(let [l (next-line)] | |
(try (cond (str/starts-with? l "(") | |
(prn (load-string l)) | |
(fs/which (str (read-string l))) | |
(load-string (format "(bbsh/%% %s)" l)) | |
:else (prn (load-string l))) | |
(catch Exception e (println (ex-message e)))) | |
(recur)))) | |
(ns user | |
(:require [bbsh :refer [%]])) | |
(bbsh/run-shell) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Demo at https://twitter.com/borkdude/status/1530170810757009412