Skip to content

Instantly share code, notes, and snippets.

@borkdude
Last active May 27, 2022 14:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save borkdude/d7e5647d77b27a664bd6135e68cccbaf to your computer and use it in GitHub Desktop.
Save borkdude/d7e5647d77b27a664bd6135e68cccbaf to your computer and use it in GitHub Desktop.
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

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