Skip to content

justone/bb-scripts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

  • highlight - Highlight regex matches in piped text.
  • 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 env does, but it masks variables that it thinks are private (like SLACK_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 bb

(require '[babashka.deps :as deps])
(deps/add-deps '{:deps {justone/bb-scripts {:local/root "."}}})
(require '[foo])

(when (= *file* (System/getProperty "babashka.file"))
  (apply foo/-main *command-line-args*))

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 Babashka
  • clojure -M:clj -m foo [args] - to test running in Clojure

Running tests

To run tests with Babashka:

bb test

To run tests with Clojure:

clojure -M:clj:test

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 from the foo script, just run:

./scripts/uberscriptify --script foo

And the resulting file will be in uberscripts/foo.

About

Development incubator for Babashka scripts

Resources

License

Stars

Watchers

Forks

Packages

No packages published