This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-09-14
Channels
- # ai (3)
- # babashka (45)
- # beginners (81)
- # biff (26)
- # calva (10)
- # cider (5)
- # clj-kondo (55)
- # cljfx (6)
- # clojure (125)
- # clojure-berlin (1)
- # clojure-europe (37)
- # clojure-italy (7)
- # clojure-nl (3)
- # clojure-norway (79)
- # clojure-uk (1)
- # clojurescript (63)
- # clojutre (1)
- # conjure (5)
- # cursive (37)
- # data-science (1)
- # datalevin (4)
- # datomic (28)
- # eastwood (6)
- # fulcro (26)
- # graphql (20)
- # honeysql (6)
- # humbleui (4)
- # jobs-discuss (5)
- # kaocha (1)
- # leiningen (8)
- # missionary (5)
- # nbb (4)
- # observability (3)
- # off-topic (7)
- # pathom (8)
- # podcasts-discuss (1)
- # rewrite-clj (18)
- # ring (6)
- # sci (23)
- # scittle (9)
- # shadow-cljs (49)
- # squint (10)
- # testing (11)
- # xtdb (17)
good afternoon 🙂 I have a tiny bookmarks-as-json system built with json, python and rofi. I'm considering rewriting the Python in Clojure. Have anyone of you shelled out to rofi from a Babashka script before? --- A quick search gave me ralphie.rofi[1], which was kind of interesting. I'm also including the Python source. It's a quick and dirty script, but it works. [1]: https://github.com/russmatney/ralphie/blob/master/src/ralphie/rofi.clj
Hi again 🙂
I'm trying to shell out to fzf
with babashka.process/process
. Would appreciate some help, details in thread.
;; I'm able to shell out to grep with both babashka.process and bash.
;; bash:
;;
;; $ grep no <<EOF
;; no u
;; lol u
;; EOF
;;
;; Press enter, and watch:
;;
;; no u
;; translated to babashka.process:
(let [in-str
"no u
lol u"]
(-> @(process/process ["grep" "no"]
{:in in-str
:out :string})
:out))
;; ... works as expected.
;; I'm able to shell out to fzf with bash:
;;
;; $ fzf <<EOF
;; no u
;; lol u
;; EOF
;;
;; ... here we can select the right candidate interactively ...
;;
;; lol u
;; But when I try with babashka.process, I'm not able to select anything interactively:
(let [in-str
"no u
lol u"]
(-> @(process/process ["fzf"]
{:in in-str
:out :string})
:out))
Any idea why that did the trick? I didn't expect that "inheriting stderr" would fix fzf interactivity.
Never knew that before now. But it makes sense, considering how you can control both stdin and stdout. Thanks!
TIL tiny fzf wrapper for babashka scripts (thanks @borkdude)
(defn fzf [options]
(-> @(process/process ["fzf"] {:in (str/join "\n" options)
:out :string
:err :inherit})
:out
str/trim))
(let [choice (fzf ["option A" "option B"])]
(println "You picked:" choice))
;; Prints
;;
;; You picked: option B
Is there a way to have universal babashka tasks? I'm thinking of creating an alias for bb -f ~/bb.edn
or similar, but am I missing a better option?
@actuallyalys_slack Maybe you're looking for #babashka-bbin which allows you to install scripts in your system so you can call them from anywhere
Ahh, I had missed that babashka project. 🙂 That might work well, if I create a little babashka project to house my little babaska snippets.
btw, I don't recommend to put a bb.edn
file in ~
: clojure-lsp might mistake it for a project root :)
I wrote a small thing.
Bink: Bookmarks are just data
idea: bookmarks are just data, and should be treated as such. To get started, we need a tool to open bookmarks from files. That's bink
.
https://play.teod.eu/bink/
Powered by babashka, babashka.process, fzf and EDN (all great tools)
Comments/questions welcome 🙂
---
You can install bink
with #babashka-bbin (by @rads):
$ bbin install
$ bink
here's the whole source:
(ns bink
(:require [babashka.fs :as fs]
[clojure.edn :as edn]
[babashka.process :as process]
[clojure.string :as str]))
(defn providers []
;; Per 2022-09-14, we only support EDN links.
(let [support-json false]
(if support-json
(fs/glob (fs/expand-home "~/.config/bink/provider") "*.{edn,json}")
(fs/glob (fs/expand-home "~/.config/bink/provider") "*.edn"))))
(defn all-links []
(mapcat (fn [p]
(:links (edn/read-string (slurp (str p)))))
(providers)))
(defn fzf [options]
(-> @(process/process ["fzf"] {:in (str/join "\n" options)
:out :string
:err :inherit})
:out
str/trim))
(defn firefox [url]
(process/process ["firefox" url]))
;; get links
(let [links (all-links)
links-by-title (into {}
(for [l links]
[(:title l) l]))
_ (assert (= (count links) (count links-by-title)) "Duplicate titles are not allowed")
choice-title (fzf (map :title links))
choice (get links-by-title choice-title)
_ (firefox (:href choice))
])
Not sure, haven't had the chance to provide a bbin-installable script before. I can have a look.
Quick status:
1. Got bbin
installed. I'm using GRML ZSH config (https://grml.org/zsh/), so I had to read install scripts to understand what they were doing in order to understand how to install bbin.
2. Had to wait a while for a full system update. bbin required a later babashka version than the one I had installed
3. Looked for docs on how to make my script available for install with bbin, coudn't find any
4. Just tried bbin install
, which worked!
So to install with bbin:
$ bbin install
@U3X7174KS I got:
Visiting /Users/borkdude/.config/bink/provider failed
anyway, the bbin install worked, but the docs should probably be more clear than just give brief examples without any comments
Yeah, super rough edges so far.
I tried browse-url
first, but I couldn't get it working. I assumed it wasn't included in babashka, but perhaps it is?