Skip to content

Instantly share code, notes, and snippets.

Last active May 27, 2022
What would you like to do?
Fun (non-serious) small shell in babashka
#!/usr/bin/env rlwrap bb
(ns bbsh
[babashka.fs :as fs]
[babashka.process :as process]
[clojure.string :as str]))
(defmacro % [& args]
`(do @(process/$ {:inherit true} ~@args)
(defn next-line []
(print (str *ns* "> "))
(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))))
(ns user
(:require [bbsh :refer [%]]))
Copy link

borkdude commented May 27, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment