babashka

https://github.com/babashka/babashka. Also see #sci, #nbb and #babashka-circleci-builds .
n2o 2021-05-11T08:49:09.191200Z

Hi, I need some rubberducks I think 😄 I want to use echo within a shell command, but want to pass -en as a Parameter. But it seems as if the shell command does not interpret -en as Parameter

(sh "echo" "-en" "foo\n\n")
=> {:exit 0, :out "-en foo\n\n\n", :err ""}
As we can see in :out the -en Parameter seems to be interpreted as the String, which shall be echoed, but not as a Parameter for echo. Can anybody help me with this? In general, I want to pipe this output to another command. I am also trying process, but there’s the same problem with the -en .

n2o 2021-05-11T08:51:03.191300Z

process, which should then be used for pipelining, provides similar results:

(-> (process '[sh -c "echo -en $FOO"] {:env {:FOO "BAR"}}) :out slurp)
=> "-en BAR\n"

n2o 2021-05-11T08:52:50.191500Z

Expected output: Something like this, without -en:

borkdude 2021-05-11T09:00:23.191900Z

@n2o The issue may be that echo is both a built-in shell command and echo being a binary on your system. Shelling out from Java always means it's calling the binary

borkdude 2021-05-11T09:01:24.192100Z

What is the purpose of echo -en foo ?

borkdude 2021-05-11T09:02:04.192300Z

For piping you can find some advice here: https://clojurians.slack.com/archives/CLX41ASCS/p1620595628139900

n2o 2021-05-11T09:03:20.192600Z

The complete script looks something like this:

(-> (process '[echo -en $SIGNATURE] {:env {:SIGNATURE "something"}})
    (process '[openssl sha1 -hmac $SECRET -binary] {:env {:SECRET "some other stuff"}})
    (process '[base64])
    :out slurp)
To upload a file to my minio server

borkdude 2021-05-11T09:04:15.192800Z

Note that this does work for me:

$ bb -e '@(:out (babashka.process/process ["echo" "-n" "foo\n\n"] {:out :string}))'
"foo\n\n"
Just the -e doesn't work, it's also not mentioned in the man echo page on my system

borkdude 2021-05-11T09:05:04.193Z

Why don't you just feed the env var to :in ?

n2o 2021-05-11T09:05:37.193200Z

I tried several different things 😄 also using :in. But I think the first problem is the en parameter

borkdude 2021-05-11T09:07:06.193400Z

Try:

@(:out (process ["openssl" "sha" "-hmac" <your-secret> "-binary"] {:in "something" :out :string})

borkdude 2021-05-11T09:07:31.193600Z

you don't have to pipe something via echo to stdin of another process, you can do that directly

n2o 2021-05-11T09:08:20.193800Z

yes, i hoped so, but the resulting base64 encoded string differs from the one when I put it directly on the console. And I was figuring out the root cause of this 😬

n2o 2021-05-11T09:08:29.194Z

thanks, I’ll give it a try.

borkdude 2021-05-11T09:09:15.194200Z

btw, there is also https://github.com/babashka/pod-babashka-buddy if you don't want to shell out

n2o 2021-05-11T09:10:48.194600Z

Yep, I think I’ll switch to some of your pods, seems easier.

borkdude 2021-05-11T09:10:51.194800Z

$ bb -e '@(:out (babashka.process/process ["openssl" "sha1" "-hmac" "dude" "-binary"] {:in "foobar" :err :inherit :out :string}))'
"/��B1SKsi�Ӕ @�\n��"

borkdude 2021-05-11T09:12:19.195600Z

$ bb -e '(-> (babashka.process/process ["openssl" "sha1" "-hmac" "dude" "-binary"] {:in "foobar" :err :inherit}) (babashka.process/process ["base64"] {:out :string}) deref :out)'
"L6UQkkIxU0tzaROn05QgQKkKg90=\n"

borkdude 2021-05-11T09:12:32.195900Z

(might want to remove the newline)

n2o 2021-05-11T09:13:28.196500Z

oh jeah, there it is… Now it is working! Thanks!

borkdude 2021-05-11T09:13:38.196700Z

hmm, I see it is different yes

n2o 2021-05-11T09:13:54.197Z

but that’s the base64 encoded string I was looking for (on my machine)

holmdunc 2021-05-11T09:13:59.197200Z

Is there something in the babashka/sci universe that can print a list of the names of the :aliases in the nearest deps.edn file?

borkdude 2021-05-11T09:14:19.197300Z

perhaps it's because of the newline of openssl

borkdude 2021-05-11T09:14:28.197500Z

neh

borkdude 2021-05-11T09:15:05.197900Z

@duncan540 not really built-in, you can just parse the edn

borkdude 2021-05-11T09:15:40.198Z

@n2o oooh:

$ bb -e '(-> (babashka.process/process ["openssl" "sha1" "-hmac" "dude" "-binary"] {:in "foobar\n" :err :inherit}) (babashka.process/process ["base64"] {:out :string}) deref :out)'
"89CMnuc40b7mfZpt9domvGCGIm0=\n"

borkdude 2021-05-11T09:15:51.198200Z

$ echo foobar | openssl sha1 -hmac dude -binary | base64
89CMnuc40b7mfZpt9domvGCGIm0=

borkdude 2021-05-11T09:15:55.198400Z

you see, that's the same...

n2o 2021-05-11T09:16:07.198600Z

yes yes, I’ve got it now working on my machine 🙂

borkdude 2021-05-11T09:16:09.198900Z

:)

n2o 2021-05-11T09:16:29.199400Z

I can also produce the same string. Thank you very much! although I currently do not see the difference from my previous approaches :thinking_face: 🤷

borkdude 2021-05-11T09:16:48.199900Z

the difference I found was that when you add a newline to the input it's the same as on the command line

borkdude 2021-05-11T09:17:14.200300Z

probably echo also adds a newline to the input

n2o 2021-05-11T09:17:17.200500Z

but I was working in a babashka script and defed the symbol with the newlines

n2o 2021-05-11T09:17:25.200700Z

so they were always present in my script

borkdude 2021-05-11T09:17:30.201Z

This is without the newline:

$ echo -n foobar | openssl sha1 -hmac dude -binary | base64
L6UQkkIxU0tzaROn05QgQKkKg90=

borkdude 2021-05-11T09:17:47.201400Z

and that's the same as the first example we had

borkdude 2021-05-11T09:18:12.202Z

$ bb -e '(-> (babashka.process/process ["openssl" "sha1" "-hmac" "dude" "-binary"] {:in "foobar" :err :inherit}) (babashka.process/process ["base64"] {:out :string}) deref :out)'
"L6UQkkIxU0tzaROn05QgQKkKg90=\n"

borkdude 2021-05-11T09:18:27.202300Z

so the confusion comes from the newlines :)

n2o 2021-05-11T09:18:29.202600Z

Okay, I understand. Great 🎉 again something learned

holmdunc 2021-05-11T09:18:44.203Z

I'm doing it from a Python context, so the best I can think of so far is to use the use Python stdlib to find the nearest deps.edn on the filesystem, then use your jet tool to transform that to JSON, then pick out the alias names from that

n2o 2021-05-11T09:18:53.203100Z

and now piping works as expected in babashka 🥳 thanks

borkdude 2021-05-11T09:19:24.203600Z

@duncan540 I have an example here to download all deps from all aliases: https://github.com/babashka/babashka/blob/master/examples/download-aliases.clj

borkdude 2021-05-11T09:19:49.204100Z

oh Python, hmm, I guess you could just shell out to bb from python as well

💡 1
borkdude 2021-05-11T09:19:59.204400Z

or use #jet that's also possible

holmdunc 2021-05-11T09:20:32.204900Z

yeah, I'll be able to cobble something together, thanks for the pointer 🙂

holmdunc 2021-05-11T12:52:37.205300Z

Sublime Text GUI plugin:

borkdude 2021-05-11T13:05:03.205700Z

Awesome :)

pithyless 2021-05-11T13:43:10.207Z

I'm having a problem moving my tasks into a local project root. 🧵

pithyless 2021-05-11T13:43:44.207100Z

If I have a bb.edn with:

{:deps
  {some.lib {:local/root "lib/some.lib"}}

  :requires ([some.lib.foo :as foo]) ;; foo is requiring lread.status-line

  :tasks {bar (foo/bar)}}

pithyless 2021-05-11T13:43:58.207300Z

Where lib deps.edn has:

{:deps
  {lread/status-line {:git/url "<https://github.com/lread/status-line.git>"
                      :sha     "35ed39645038e81b42cb15ed6753b8462e60a06d"}}}

pithyless 2021-05-11T13:44:14.207500Z

Then we get an error when running bb bar:

Type:     java.lang.Exception
Message:  Could not find namespace: lread.status-line.

pithyless 2021-05-11T13:44:33.207700Z

But if I add that status-line dependency directly to bb.edn's :deps everything works. Am I doing something wrong or is there some bug between the interplay of deps and tasks?

borkdude 2021-05-11T13:44:52.207900Z

no, this is by design. bb deps should go into bb.edn

borkdude 2021-05-11T13:45:15.208100Z

this used to work by mistake

borkdude 2021-05-11T13:45:27.208300Z

but the Clojure deps should not be mixed with bb deps imo

pithyless 2021-05-11T13:46:06.208500Z

hmm, yeah, so this did used to work and I'm not going crazy; I depended on the behavior :]

pithyless 2021-05-11T13:46:49.208700Z

I don't understand this design decision - if I would like to publish a task as a reusable piece of code that can be used by multiple bb.edns, how should I go about it?

borkdude 2021-05-11T13:46:51.208900Z

yeah, it was accidental

borkdude 2021-05-11T13:47:14.209100Z

then you could make that reusable piece of code a library I guess?

pithyless 2021-05-11T13:47:52.209300Z

and that lib would be imported via :deps in bb.edn, correct?

borkdude 2021-05-11T13:47:54.209500Z

oh, you would like to publish a task as a reusable piece of code, I didn't anticipate that use case

borkdude 2021-05-11T13:48:04.209700Z

I mean, the task name etc?

borkdude 2021-05-11T13:48:13.209900Z

or just some functions?

pithyless 2021-05-11T13:48:29.210100Z

no, just some functions that a task can call

borkdude 2021-05-11T13:48:40.210300Z

yes, you can use any library in :deps, same as deps.edn, but specific for bb

borkdude 2021-05-11T13:49:13.210500Z

so you can e.g. use :local/root or :paths to get at the shared code or if you want to publish it, use :git/url

pithyless 2021-05-11T13:49:26.210700Z

yep, that's what I'm trying to do

pithyless 2021-05-11T13:49:50.210900Z

it's like bb is not resolving the deps inside the :local/root deps.edn when calling tasks

borkdude 2021-05-11T13:50:19.211100Z

bb isn't resolving deps from deps.edn at all

borkdude 2021-05-11T13:50:54.211300Z

or do you mean, the deps.edn from the local/root library?

borkdude 2021-05-11T13:50:59.211500Z

that should work

pithyless 2021-05-11T13:51:17.211700Z

no, when bb has an entry {:deps {foo :local/root "foo"}} -> it's not resolving the "foo/deps.edn"

borkdude 2021-05-11T13:51:40.211900Z

it should be {:deps {foo {:local/root "foo}}}

borkdude 2021-05-11T13:52:17.212100Z

it might be a caching issue, maybe try rm -rf .cpcache; rm -rf ~/.clojure/.cpcache

pithyless 2021-05-11T13:53:33.212300Z

🤦 that did it

borkdude 2021-05-11T13:54:20.212500Z

it was the caching issue?

pithyless 2021-05-11T13:54:37.212700Z

Yep, state. Mutable state is always the problem.

pithyless 2021-05-11T13:55:02.212900Z

maybe bb needs a -Srepro ? XD

borkdude 2021-05-11T13:55:31.213100Z

cache is turned off with -Sforce but yeah, we should allow passing args down to the deps tool

pithyless 2021-05-11T13:56:34.213300Z

anywho, thanks @borkdude - I was starting to doubt my sanity

borkdude 2021-05-11T13:57:30.213500Z

:) you can debug the classpath with (babashka.classpath/get-classpath)

pithyless 2021-05-11T13:59:54.213700Z

I used to always add -Sforce -Srepro to all my Makefiles out of habit just to reduce these vectors of confusion

pithyless 2021-05-11T14:00:39.213900Z

(although that comes with its own set of drawbacks)

borkdude 2021-05-11T17:55:13.214500Z

if you have some ideas how babashka could pass down args to the deps system...

borkdude 2021-05-11T17:55:50.214700Z

bb --deps -Sforce --deps -Srepro ... run foo
or so...

borkdude 2021-05-11T17:57:24.215200Z

or directly support the relevant CLI args...

bb -Sforce run foo

borkdude 2021-05-11T17:58:13.215400Z

some prefix would be good probably to not get conflicts with prior or future bb args

borkdude 2021-05-11T17:58:32.215600Z

like -J-Dfoo=bar but then something else

borkdude 2021-05-11T17:58:40.215800Z

-C-Sforce

metehan 2021-05-11T19:11:59.216900Z

I couldn't install babashka on ubuntu (pop-os)

r@pop-os:~/dev/babashka/babashka$ script/uberjar &amp;&amp; script/compile
openjdk version "1.8.0_292"
OpenJDK Runtime Environment (build 1.8.0_292-8u292-b10-0ubuntu1~20.04-b10)
OpenJDK 64-Bit Server VM (build 25.292-b10, mixed mode)
Syntax error (ClassNotFoundException) compiling at (babashka/impl/classes.clj:345:20).
java.lang.ProcessHandle

Full report at:
/tmp/clojure-2871116251297672484.edn
Error encountered performing task 'do' with profile(s): 'base,system,user,provided,dev,xml,yaml,core-async,csv,transit,httpkit-client,httpkit-server,core-match,hiccup,test-check,rewrite-clj,selmer,reflection'
Suppressed exit

metehan 2021-05-11T19:13:35.217Z

https://pastecode.io/s/4qfA31CkP3

borkdude 2021-05-11T19:20:32.217200Z

you need graalvm 21.1.0 CE JDK11

❤️ 1
borkdude 2021-05-11T19:21:40.217800Z

btw why are you trying to build it yourself rather than downloading the binary?

metehan 2021-05-11T19:28:09.218Z

yes I was trying to build myself somehow I didn't see the binaries 🙂

metehan 2021-05-11T19:28:13.218200Z

thank you

metehan 2021-05-11T19:28:42.218500Z

I installed with asdf now

borkdude 2021-05-11T19:28:44.218700Z

ok, just letting you know that bb is available as binaries, so only if you are developing you have to build it yourself

borkdude 2021-05-11T19:28:52.218900Z

:thumbsup:

🍺 1
n2o 2021-05-11T19:47:33.219900Z

Are there any autocompletion features for the shell to access aliases from the Task Runner? If not, I’d love to have more support in the shell to have it tab-autocompleted 😄

borkdude 2021-05-11T19:48:10.220700Z

@n2o there have been some experimental approaches, I'd love to see contributions for this so we can support bash and zsh (and others, but I'm using zsh)

borkdude 2021-05-11T19:48:25.220900Z

@n2o https://github.com/russmatney/bb-task-completion

n2o 2021-05-11T19:48:52.221600Z

ah, perfect. I’ll take a look at this, Sadly, I am using fish, but maybe we can work on that / I can help you with that

borkdude 2021-05-11T19:49:53.222200Z

here's also some other approach: https://github.com/jeroenvandijk/matryoshka

borkdude 2021-05-11T19:50:42.223100Z

I'm fine with supporting any shell, but I haven't had the time to look into this myself and I think this would be a good place to contribute

borkdude 2021-05-11T19:50:59.223400Z

Perhaps the completion script can be written in bb itself?

borkdude 2021-05-11T19:51:12.223900Z

or can bb emit some hints to the shell itself via some subcommand? Not sure how this should work

n2o 2021-05-11T19:51:14.224100Z

that’s what I was thinking about 😄

borkdude 2021-05-11T19:51:53.224700Z

Shells should be able to ask to a binary: bb --complete &lt;substring&gt; and it will give a list of completions, or something like this right

n2o 2021-05-11T19:54:06.225500Z

Jep, sounds great, thanks for the pointers. interesting that these repos are recently created

borkdude 2021-05-11T20:19:32.225900Z

https://twitter.com/avidrucker/status/1392202960256606208

👀 1
❤️ 2
Jakub Holý 2021-05-12T08:09:09.234800Z

@avidrucker Hi! regarding ☝️ and the "replacements to mv, rm, and cp", it would be also note pointing to the more ergonomic https://babashka.org/fs/babashka.fs.html#var-copy included with bb: bb -e '(babashka.fs/copy "server.pem" "server.pem.copy")'