This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-10-05
Channels
- # announcements (19)
- # babashka (28)
- # beginners (62)
- # biff (3)
- # calva (19)
- # cider (24)
- # clj-kondo (8)
- # cljdoc (15)
- # clojure (32)
- # clojure-europe (16)
- # clojure-nl (1)
- # clojure-norway (17)
- # clojure-uk (8)
- # clojuredesign-podcast (26)
- # cursive (64)
- # datomic (43)
- # deps-new (1)
- # fulcro (4)
- # honeysql (1)
- # hyperfiddle (46)
- # kaocha (16)
- # lsp (15)
- # missionary (51)
- # music (1)
- # nbb (4)
- # off-topic (55)
- # pedestal (11)
- # podcasts-discuss (1)
- # polylith (7)
- # practicalli (1)
- # releases (4)
- # shadow-cljs (120)
- # tools-build (34)
- # vscode (1)
- # xtdb (2)
https://github.com/eerohele/pp (v2023-10-05.5) is a pretty fast, single-namespace, no-dependency lib for pretty-printing Clojure/EDN data (not code). It is primarily meant for tools that need to pretty-print Clojure evaluation results, but might be useful any time you need to pretty-print something fast.
This is great!
Small ✔️ , fast ✔️ , zero dependency ✔️. Looks good to me!
pp works in bb
$ rlwrap bb -Sdeps '{:deps {io.github.eerohele/pp {:git/tag "2023-10-05.5", :git/sha "7059eec"}}}'
Cloning:
Checking out: at 5f7c68b70aea31561df62d0a56d8396dae8cc9d0
Babashka v1.3.185-SNAPSHOT REPL.
Use :repl/quit or :repl/exit to quit the REPL.
Clojure rocks, Bash reaches.
user=> (require '[me.flowthing.pp :as pp])
nil
user=> (pp/pprint {:a 1 :b 2 :c 3 :d 4} {:max-width 10})
{:a 1,
:b 2,
:c 3,
:d 4}
nil
Is there a bb way to call pp as a oneline bash call? Taking raw EDN from standard in and pretty printing it to standard out.
$ bb '(zipmap (range 10 ) (range 10))' |
bb -Sdeps '{:deps {io.github.eerohele/pp {:git/tag "2023-10-05.5", :git/sha "7059eec"}}}' -e "((requiring-resolve 'me.flowthing.pp/pprint) (clojure.edn/read-string (slurp *in*)) {:max-width 5})"
{0 0,
7 7,
1 1,
4 4,
6 6,
3 3,
2 2,
9 9,
5 5,
8 8}
@U4ZDX466T Maybe good to add to non-goals: colored output (assuming you don't want this)
It works! Excellent I've added this as a an alias epp
to my bash
alias epp='bb -Sdeps '"'"'{:deps {io.github.eerohele/pp {:git/tag "2023-10-05.5", :git/sha "7059eec"}}}'"'"' -e "((requiring-resolve '"'"'me.flowthing.pp/pprint) (clojure.edn/read-string (slurp *in*)) {:max-width 5})"'
bb '(zipmap (range 10 ) (range 10))' | epp
{0 0,
7 7,
1 1,
4 4,
6 6,
3 3,
2 2,
9 9,
5 5,
8 8}
Will be very handy for working with EDN from REST and in files. (`curl https://example.com/abc.edn | epp` etc)
Heh, pp does seem to work in bb, yes. 👍 The tests have some Clojure-specific things (as well as Transcriptor, which is Clojure-only), but those shouldn't be too difficult to sort out. I have an issue on that.
@U04V15CAJ Good idea, thanks! Will add. 👍
Although I suppose I could also release Tab's syntax highlighter as a standalone lib... that would make it pretty straightforward to add color support, too. Would just need to make it output ANSI escape sequences in addition to Hiccup/HTML. :thinking_face:
Nice! I'll put that to use too.
we now use it on https://github.com/exoscale/lingo (for clj, not cljs)