Scripting with janet
Writing small scripts for my own use has always been fun, but I have always felt like I wanted a different language than bash or python. And now I have found it, Janet!
I have been using taskwarrior for a while, and with that comes small scripts and tweaks to improve my setup. Most of those scripts are oneliners in bash which is fine, that is what bash is good for. But sometimes a need a little bit more control.
My last tiny problem is that I needed to map a string of the following format "bar,foo" to "+bar +foo". I actually dont know how I would do that in bash, but it would for sure not be as fun as doing this in Janet.
#!/usr/bin/env janet
(defn fromInput [args]
"Either return stream from stdin or first argument given"
(if (= (length args) 1)
(do
(def buf @"")
(file/read stdin :line buf)
buf)
(get args 1)))
(defn main [& args]
(->>
(fromInput args)
(string/replace "\n" "")
(string/split ",")
(filter |(not= "" $0))
(map |(string "+" $0))
(|(string/join $0 " "))
(prin)))