Fork me on GitHub
#babashka
<
2022-04-02
>
apt14:04:31

Hi folks. Is it possible to reproduce something like this in bb?

#!/bin/bash
printf "%s\n%s" foo bar  | fzf
fzf [1] displays foo and bar in a list of options, and the user selects one option. I’d like to get the return value as well. I tried using this but the output is not visible:
(sh "bash" "-c" "printf \"%s\n%s\" foo bar  | fzf")
[1]: https://github.com/junegunn/fzf

1
borkdude14:04:06

Are you trying to call fzf from within a bb script, or are you trying to pipe the output from bb into fzf?

apt14:04:39

The first option. The bb script is supposed to be used interactively. It will fetch some data, present it to the user thru fzf, and do stuff with the selection.

borkdude14:04:38

Maybe that helps

borkdude14:04:14

To call fzf with a string, you can call

(fzf "a\nb\nc\n")
for example and it will offer only those completions

apt14:04:06

Yeap, that’s exactly what I was testing here 🙂 Thanks!

David Pham07:04:52

Will you include automatically in bb?

borkdude07:04:10

No, the point is that it runs from source. We could have included it as a built-in ages ago, but it runs from source so we don't have to.

teodorlu18:04:02

Hey! Using neil, I frequently get the latest version of a library - like org.clojure/clojure {:mvn/version "1.11.1-rc1"} or hiccup/hiccup {:mvn/version "2.0.0-alpha2"} - when I really wanted Clojure 1.11.0 or Hiccup 1.0.5. If we had a way to list out versions, we could fuzzy-search on that, and pipe the result into an "add to deps.edn" command. I gave it a shot, and got it working with Clojars. Source: https://github.com/teodorlu/neil. A bit of messy discussion in . Open questions: • What about Maven and Git? • neil add dep vs neil dep add? I didn't find a neat place to put neil dep versions in the default CLI structure to put version listing. But backwards compatibility is also good. • Separating version selection from adding a dependency is one way forward. Another way is to provide a version selection command to neil add dep, supporting stuff like neil add dep hiccup/hiccup :select-cmd fzf. Not sure if this is something other people would like? Thoughts/comments?

borkdude18:04:26

@U3X7174KS I love it

❤️ 1
borkdude18:04:51

Personally I find neil add dep :lib too long and I've wanted to change it to something more intuitive shorter.

borkdude19:04:34

We could add automatic fzf support if we can find fzf on the path (using babashka.fs/which, it works cross platform)

borkdude19:04:11

neil deps add :lib ... :version ...
neil add :lib :version

👀 1
borkdude19:04:32

we could try to dispatch on one of the present keywords, if :lib is present, we assume you want to add a dep

👀 1
teodorlu19:04:17

> We could add automatic fzf support if we can find fzf on the path (using babashka.fs/which, it works cross platform) There's lots of other options for selection too, though. Rofi is one. Example:

neilz dep versions hiccup/hiccup | rofi -dmenu | xargs neilz dep add
Personally, I prefer fzf. It stays in the terminal, and is fast.

borkdude19:04:14

We could do fzf support and if fzf is not present, you maybe get a list of options and you can type a number?

borkdude19:04:55

Also, personally I'm not interested in all versions back to the beginning of a library, usually the top 10 is ok for me

teodorlu19:04:38

Now you're considering building shelling out til fzf straight into neil add dep? WIth the pipe solution, neil doesn't need to know about fzf.

borkdude19:04:11

True,. we could also just support that initially

teodorlu19:04:12

> Also, personally I'm not interested in all versions back to the beginning of a library, usually the top 10 is ok for me Same for me, seems to be approximately what the clojars API gives in :recent_versions

teodorlu19:04:10

We'd still need a place to fit the version listing into neil's CLI, though. What do you think about that? Assuming that we can find a solution for Git and Maven deps.

borkdude19:04:58

It already does maven deps, from central

borkdude19:04:23

But no list, true

teodorlu19:04:44

(I didn't spend any time looking up their HTTP API)

borkdude19:04:37

I'm for adding this. If you could start chopping this up in tiny manageable issues and after some agreement, tiny manageable PRs, would be great :)

teodorlu19:04:39

Working on the bb script was a joy, by the way. I started a reload loop:

rg --files | entr -rc bash -c "bb gen-script && neilz addz dep :lib hiccup/hiccup"
and printed here and there to see what was happening.

teodorlu19:04:19

> I'm for adding this. If you could start chopping this up in tiny manageable issues and after some agreement, tiny manageable PRs, would be great 🙂 My schedule is somewhat unpredictable at the moment, but I'd be happy contributing what I can!

borkdude19:04:39

Unpredictable is not a problem :)

👍 1
teodorlu19:04:53

> chopping this up in tiny manageable issues Any suggestions for what kinds of issues? "CLI for listing available versions of library"? More?

borkdude19:04:26

Yep, that one is the main one right?

borkdude19:04:35

And maybe a more intuitive way to call neil

👍 1
teodorlu19:04:38

Issue: CLI for listing available versions of a library https://github.com/babashka/neil/issues/16

teodorlu20:04:10

Not sure what the %22 stuff in the maven search URLs are. Does it casuse exact matches rather than "string contains"? https://github.com/babashka/neil/blob/65b5508a8496abe4d3a7168205b211760e9f4a8a/src/babashka/neil.clj#L25

teodorlu20:04:57

Got it working for Maven coordinates:

$ neilz dep versions :lib org.clojure/clojure
:lib org.clojure/clojure :version 1.11.1-rc1
:lib org.clojure/clojure :version 1.11.0
:lib org.clojure/clojure :version 1.11.0-rc1
:lib org.clojure/clojure :version 1.11.0-beta1
...
I've got a feeling that version count should probably be configurable.

borkdude20:04:19

Don't know where I got that URL from anymore

👍 1
ordnungswidrig21:04:24

scittle allows for quick fun with reagent ❤️ https://codepen.io/ordnungswidrig/pen/xxpPYNO (I wanted to generate such 3d effect mosaic background for some print design. Reagent and some CSS was the quickest I could think of. I could’t resist and animate it 😛 )

🎉 2
🆒 1
2
borkdude21:04:54

Very nice! Also shared this in #scittle