bb-scripts
bb-scripts copied to clipboard
Development incubator for Babashka scripts
bb-scripts
Development incubator for Babashka scripts. This is where I develop scripts in Clojure and then run them with Babashka.
I gave a presentation about writing scripts in Babashka. Slides are here.
Current scripts
- empath - Print out and edit
$PATH-like things. - ftime - Print out a human-readable time based on passing in millis.
- penv - Prints out the environment like
envdoes, but it masks variables that it thinks are private (likeSLACK_TOKEN). - comb - Template data using comb.
Using the scripts
Manual
If you only want to use one of the scripts, just download it out of the
uberscripts directory and put it in a directory on your
$PATH.
Install with bbin
bbin is a great way to install Babashka scripts with one command.
It doesn't yet support picking
which script you want when a repo (like this one) supports multiple, so use the
following syntax (provide --main-opts and --as):
bbin install io.github.justone/bb-scripts --main-opts '["-m" "empath"] --as empath
Refer to the bbin docs for more options.
Development Workflow
Set up
Before you begin development, you should have the following installed on your PATH:
Creating a script
To create a script, you need to create two files. For instance, to create a new script called foo, create the following files:
script/foo - a Babashka dev runner
#!/usr/bin/env bash
cd $(dirname $0)/..
bb -cp $(clojure -Spath) -m foo -- "$@"
src/foo.clj - the Clojure source for the script
(ns foo)
(defn -main [& args]
(println "foo"))
Development
Start a repl with clojure -X:clj:repl. This will expose nREPL and pREPL ports
for editor integration. This allows for full iterative REPL-driven development.
To test running the script as a whole, use either of the following:
./script/foo [args]- to test running in Babashkaclojure -M:clj -m foo [args]- to test running in Clojure
Uberscripting
Babashka can combine all namespaces used by a script into one file called an uberscript. There is a script in ./scripts/uberscriptify that will combine this with the proper header. To create an uberscript, just run:
./scripts/uberscriptify -s foo
And the resulting file will be in uberscripts/foo.