Fork me on GitHub
#babashka
<
2024-01-27
>
dabrazhe13:01:33

Copilot knows about babashka )

🎉 2
Felix Dorner15:01:21

Is there a crossplatform way to copy something to clipboard?

borkdude16:01:19

If you search this channel for "clipboard" you will find some options clipboard in:#babashka

Felix Dorner13:01:37

Ok not so easy then. I’ll work around it.

Omer ZAK15:01:54

tl;dr: Prompting for passwords from a Babashka script, anyone? I am developing a Babashka script, and I want it to run a shell command (specifically cryptsetup luksOpen) which prompts for a password. Of course, I do not want the script to echo the password in plaintext when the user enters it. How to get the password from the user? (I already tried asking ChatGPT but it hallucinated on it and gave me answers which did not work.)

Felix Dorner15:01:26

You could use gum input --password via https://github.com/lispyclouds/bblgum

Bob B16:01:07

if the program prompts for a password, then have the program inherit stdin should using the program's masking mechanism

borkdude16:01:42

This normally works too: https://github.com/babashka/babashka/issues/1632 but was broken in a recent GraalVM version that bb started using

borkdude16:01:14

It's fixed now so when I will upgrade to the next GraalVM version, it will work again. I'll do so before the next release. For now you can use an older release, perhaps

Omer ZAK18:01:00

@U04V15CAJ, Thanks for your reply. I have upgraded Babashka from version 1.3.186 to version 1.3.188. When trying to (.readPassword (System/console)) (and also when trying to run the script in the aforementioned issue 1632), I get the error:

java.lang.UnsatisfiedLinkError: jdk.internal.io.JdkConsoleImpl.echo(Z)Z [symbol: Java_jdk_internal_io_JdkConsoleImpl_echo or Java_jdk_internal_io_JdkConsoleImpl_echo__Z] [at <repl>:31:1]
What can I do today besides waiting for a working GraalVM version? Can I upgrade it today?

borkdude19:01:02

I've pushed a branch now with the GraalVM upgrade, you can download a test build later, I'll post a link

borkdude19:01:09

I can confirm locally that 21.0.2 fixes it: $ ./bb -e '(.readPassword (System/console))'

borkdude19:01:32

which OS are you on?

Omer ZAK20:01:50

My OS is Linux Debian 11 ("Debian Bullseye"). I also have Java 17 (`java-17-openjdk-amd64` to be precise).

Omer ZAK21:01:29

When trying to download it, my browser tells me that the site cannot be reached ("Check if there is a typo in http://38182-201467090-gh.circle-artifacts.com"). I also tried curl -o -L (like in the babashka-install script), and it too complained about the unreachable hostname.

Omer ZAK21:01:03

The next hurdle is that with babashka-1.3.189-SNAPSHOT, str does not know how to deal with the returned password data:

user=> (.readPassword (System/console))
;; (I enter 'a'. I see a single asterisk. Then I hit ENTER)
#object["[C" 0x22355512 "[C@22355512"]
When I try (str (.readPassword (System/console))) I see "[C@b490d39" (The actual numbers change each time, they seem to be related to memory addresses.)

borkdude21:01:44

It's a byte array, you can convert it to string with (String. the-bye-array "utf-8")

Omer ZAK22:01:13

user==> (String. (.readPassword (System/console)) "utf-8")
;; (I entered 'a' followed by ENTER and saw a single asterisk)
No matching ctor found for class java.lang.String
Did I miss any require or use? 🙁 Or should I somehow convert the "utf-8" string into a Charset instance?

borkdude22:01:09

probably my bad, try this:

'(String. (.readPassword (System/console)))'

borkdude22:01:13

it's a char array, not a byte array

Omer ZAK22:01:35

(String. (.readPassword (System/console)))
;; (I entered text followed by ENTER. I saw asterisks. Guess which text :-)
"By golly, it works!"

🎉 1
Omer ZAK22:01:57

@U04V15CAJ, Thanks for fixing the problem and for helping me make use of the fix. Approximately how long until the fix is officially released as a new Babashka version? (not urgent for me, just to satisfy my curiosity)

borkdude22:01:39

usually 1 release a month, so probably two weeks or so

👍 1