Fork me on GitHub
#babashka
<
2023-01-07
>
grazfather15:01:23

how do you guys set up a modeline in an extensionless file with a babashka shebang for vim? Is this correct? #_" vim: set ft=clojure:". It works but I don't want anything extra

joakimen15:01:17

Out of curiosity, what does #_" represent? I usually just go with the regular comment syntax for that given language, so ; vim: set ft=clojure:

borkdude15:01:58

@U7ERLH6JX might also know as a vim user

lispyclouds15:01:49

@U01KUQRDMLG standard clojure comment like the one @U0422G22932 said would work, (n)vim looks for set patterns in the first line, doesnt need to start with #

lispyclouds15:01:02

@U0422G22932 the #_ is the clojure reader dispatch character to ignore the next form. in this case the string following it

👌 2
lispyclouds15:01:03

can comment out forms in a form like (-> foo (bar a) #_(baz b) (quz c))

grazfather15:01:42

cool thanks. @U04V15CAJ i think you use emacs. Do you do #_"..." or ; -*- mode: clojure; -*-?

grazfather15:01:15

Yeah #_ is nice because you can comment out a form that has other forms on the same line, or a form that spans lines

borkdude15:01:16

I might have used the latter

grazfather15:01:58

have used? Are you on vscode now? 😜

borkdude15:01:32

doesn't have used mean that you're still doing it? like "have been" etc? ;-)

grazfather15:01:55

perfect tense implies an ended action

borkdude15:01:13

I have been using the latter, maybe

borkdude15:01:25

don't remember, I don't do this often

grazfather15:01:26

have been using vs. have used, the former adds a participle using to sort of reimply it's continuing 😛

borkdude15:01:01

#C0400TZENE7 takes care of this for you ;)

grazfather15:01:07

Ah, you don't use standalone chmod +x bb scripts?

grazfather15:01:11

oh. Will check it out!

borkdude15:01:53

@U01KUQRDMLG Here are some of my scripts that you can install with bbin: https://github.com/borkdude/tools

grazfather15:01:44

cool thanks again

borkdude15:01:26

I think in emacs I just enable clojure-mode manually as well, if needed. I add the mode-line for github highlighting though

joakimen15:01:29

I have a beginner-question on the organization of babashka-scripts. I have a big bucket of shell-scripts (bash) I want to reorganize and rewrite to bb. I'm used to just tossing all my scripts with a shebang and executable-flag into my $PATH, then invoking them directly from other shell-scripts. I'm not really sure how to transition into babashka for this, as requiring things involves the classpath, and including files via load-file suffers from relative path problems. I'm probably just missing some basic understanding, but how do you guys go about organizing these things? Ideally, I want to be able to write scripts as small and composable as possible, so managing metadata and deps (deps.edn, bb.edn) for every 2-3 lines of code seems heavy. Any tips or reading resources on how to approach this? I guess I could just throw a bb-shebang on them and toss them into $PATH as well, but then I'd be back to glueing them with stdout/stdin again. 🤷

lispyclouds15:01:30

I'd go with a ~/.bb.edn maybe and refer all of these scripts as tasks. then have aliases to bb --config ~/.bb.edn <task-name>

borkdude15:01:38

You can do that but you can also just write libraries to compose things together and then make script entry points to call into those libraries.

borkdude15:01:12

Btw, I don't recommend putting a bb.edn in your home root folder, since clojure-lsp etc might recognize your entire home directory as a giant clojure project

👀 1
📚 2
lispyclouds15:01:29

yeah fair point

lispyclouds15:01:14

i have my aliases pointing to a dir of bb.edn and the tasks

joakimen15:01:32

I'm not sure I know what you mean with script entry point here, do you have any articles or reference-projects to illustrate?

borkdude15:01:46

@U0422G22932 an example is lein2deps, which itself is a library but the "front-end" script uses this library. The script lives here and can be installed using #babashka-bbin

bbin install 
while the library code lives here: https://github.com/borkdude/lein2deps

borkdude15:01:24

The front-end script is just a thin wrapper:

(require '[babashka.deps :as deps])
(deps/add-deps '{:deps {io.github.borkdude/lein2deps {:git/sha "60e33d969f624143f03ebd3456a703e68c8b9ab7"}}})
(require '[lein2deps.api])
(apply lein2deps.api/-main *command-line-args*)

borkdude15:01:12

@U7ERLH6JX’s approach works well if you're not planning to have your code on github etc, but even then you could use the "library" approach using :local/root

joakimen15:01:02

Everything will be on GitHub, my primary concern is just to keep the friction of producing new scripts as low as possible, without ending up with maven-style project hierarchies for what is basically a single, independent function. I guess I just need some more experience with building proper libraries

borkdude15:01:34

I recommend checking out #C0400TZENE7

5
joakimen15:01:17

I'll take a look at your examples, yeah! Also, while you're here; I've been through several of your talks/podcasts, and I really appreciate your feedback and your work. Thank you!

❤️ 2
borkdude15:01:11

if you're writing a tool that you want to install just once, maybe it makes sense to use #C03KJHCNZ99 to implement subcommands

borkdude15:01:15

e.g.

bbin install io.github.borkdude/quickblog --tool --ns-default quickblog.api
and then:
quickblog new 
quickblog watch 
;; etc

😎 2
joakimen16:01:58

Yeah i've been using go+cobra for this previously, but babashka-cli is the best clojure-alternative I've seen for that so far