This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-05-11
Channels
- # aleph (3)
- # announcements (3)
- # aws (7)
- # babashka (121)
- # beginners (82)
- # calva (40)
- # chlorine-clover (37)
- # clj-kondo (68)
- # cljsrn (4)
- # clojure (43)
- # clojure-australia (1)
- # clojure-dev (6)
- # clojure-europe (15)
- # clojure-italy (2)
- # clojure-nl (1)
- # clojure-provo (3)
- # clojure-spec (23)
- # clojure-taiwan (1)
- # clojure-uk (21)
- # clojurescript (214)
- # code-reviews (1)
- # conjure (4)
- # core-async (10)
- # cursive (52)
- # datahike (5)
- # datascript (5)
- # datomic (62)
- # duct (1)
- # emacs (4)
- # fulcro (8)
- # graalvm (1)
- # helix (1)
- # honeysql (5)
- # integrant (1)
- # jackdaw (32)
- # jobs (3)
- # jobs-discuss (16)
- # juxt (1)
- # kaocha (3)
- # lsp (6)
- # malli (2)
- # meander (6)
- # nrepl (1)
- # off-topic (46)
- # other-languages (4)
- # pathom (7)
- # polylith (13)
- # re-frame (3)
- # releases (2)
- # shadow-cljs (56)
- # spacemacs (15)
- # tools-deps (3)
- # unrepl (1)
- # utah-clojurians (1)
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
.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 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
For piping you can find some advice here: https://clojurians.slack.com/archives/CLX41ASCS/p1620595628139900
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 serverNote 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 systemI tried several different things 😄 also using :in
. But I think the first problem is the en
parameter
Try:
@(:out (process ["openssl" "sha" "-hmac" <your-secret> "-binary"] {:in "something" :out :string})
you don't have to pipe something via echo to stdin of another process, you can do that directly
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 😬
btw, there is also https://github.com/babashka/pod-babashka-buddy if you don't want to shell out
$ bb -e '@(:out (babashka.process/process ["openssl" "sha1" "-hmac" "dude" "-binary"] {:in "foobar" :err :inherit :out :string}))'
"/��B1SKsi�Ӕ @�\n��"
$ bb -e '(-> (babashka.process/process ["openssl" "sha1" "-hmac" "dude" "-binary"] {:in "foobar" :err :inherit}) (babashka.process/process ["base64"] {:out :string}) deref :out)'
"L6UQkkIxU0tzaROn05QgQKkKg90=\n"
@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"
$ echo foobar | openssl sha1 -hmac dude -binary | base64
89CMnuc40b7mfZpt9domvGCGIm0=
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: 🤷
the difference I found was that when you add a newline to the input it's the same as on the command line
This is without the newline:
$ echo -n foobar | openssl sha1 -hmac dude -binary | base64
L6UQkkIxU0tzaROn05QgQKkKg90=
$ bb -e '(-> (babashka.process/process ["openssl" "sha1" "-hmac" "dude" "-binary"] {:in "foobar" :err :inherit}) (babashka.process/process ["base64"] {:out :string}) deref :out)'
"L6UQkkIxU0tzaROn05QgQKkKg90=\n"
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?
@duncan540 not really built-in, you can just parse the edn
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
@duncan540 I have an example here to download all deps from all aliases: https://github.com/babashka/babashka/blob/master/examples/download-aliases.clj
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)}}
Where lib deps.edn has:
{:deps
{lread/status-line {:git/url ""
:sha "35ed39645038e81b42cb15ed6753b8462e60a06d"}}}
Then we get an error when running bb bar
:
Type: java.lang.Exception
Message: Could not find namespace: lread.status-line.
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?
hmm, yeah, so this did used to work and I'm not going crazy; I depended on the behavior :]
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?
oh, you would like to publish a task as a reusable piece of code, I didn't anticipate that use case
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
it's like bb is not resolving the deps inside the :local/root
deps.edn when calling tasks
no, when bb has an entry {:deps {foo :local/root "foo"}}
-> it's not resolving the "foo/deps.edn"
cache is turned off with -Sforce
but yeah, we should allow passing args down to the deps tool
anywho, thanks @U04V15CAJ - I was starting to doubt my sanity
I used to always add -Sforce -Srepro
to all my Makefiles out of habit just to reduce these vectors of confusion
some prefix would be good probably to not get conflicts with prior or future bb args
> if you have some ideas how babashka could pass down args to the deps system...
Nothing directly comes to mind, the -C-Sforce
is interesting, because it's consistent with the approach deps.tools have taken; maybe it would be enough to have a :clojure-opts
setting in the bb.edn
?
The complexity also stems from the fact that you have the clojure
that is internal and used to resolve things like bb :deps
; but there is also the clojure
that can be invoked by a user task. If one were to pass or configure some default clojure args, should they be applied the same to both?
That’s not really an issue. clojure is a drop-in replacement to which you can pass all args
I couldn't install babashka on ubuntu (pop-os)
r@pop-os:~/dev/babashka/babashka$ script/uberjar && 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
ok, just letting you know that bb is available as binaries, so only if you are developing you have to build it yourself
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 😄
@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)
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
here's also some other approach: https://github.com/jeroenvandijk/matryoshka
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
or can bb emit some hints to the shell itself via some subcommand? Not sure how this should work
Shells should be able to ask to a binary: bb --complete <substring>
and it will give a list of completions, or something like this right
Jep, sounds great, thanks for the pointers. interesting that these repos are recently created
@U01C3LSFZAM 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")'
@U0522TWDA Thank you for this. The link unfortunately appears to be down, but searching for "bb -e" in the book https://book.babashka.org/ seems to give helpful context 👍🤓