Skip to content

Instantly share code, notes, and snippets.

@borkdude
Last active May 27, 2022
Embed
What would you like to do?
Fun (non-serious) small shell in babashka
#!/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)
@borkdude
Copy link
Author

borkdude commented May 27, 2022

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