Fork me on GitHub
#babashka
<
2021-10-28
>
Imdad Ahmed12:10:18

Are beginner questions welcome? I'm trying to (sh "brew install tree") to which i get

Cannot run program "brew install tree": error=2, No such file or directory
May be bb can't find brew on path, idk what am i missing.

borkdude12:10:06

Beginner questions are very welcome here.

borkdude12:10:25

@imdad.ahmed I recommend using (babashka.tasks/shell "brew install tree")

borkdude12:10:50

or else you'll have to split the command into chunks yourself: (sh ["brew" "install" "tree"])

Mno12:10:13

(sh (str/split "brew install tree" #" ")) 
kappa

👏 1
borkdude12:10:07

that doesn't always work correctly. there is babaskha.process/tokenize which does it more accurately

Mno12:10:45

Oh a joke turned into actually nice to know info 😮

Mno12:10:58

I really should read the libraries section of the bb book

Imdad Ahmed12:10:51

@borkdude Thanks the quick response. That worked as expected. I was able to connect to bb nrepl via my emacs setup and also verify that the function compiles etc. (Also) Thanks for the excellent documentation! Can i ask one more question: Upon cider connect to the bb nrepl, it gives a warning saying clojure version is undetermined. Is that a known issue?

borkdude12:10:21

@imdad.ahmed that is a known issue, it should be harmless, but feel free to report it to #cider

👍 1
viesti19:10:29

random hack, was wondering how to send some initialization code to application which gets started with nrepl.cmdline, something like Leiningen :init and cooked up this based on babashka book examples 🙂 https://gist.github.com/viesti/8959327b298950cd9c9574ce46265591

🎉 1
borkdude19:10:39

nREPL FTW :)

Artem19:10:06

Hello everyone! I have two files, in which one I defined a function and in the second one I call it, for example: first.clj (def some-var “123”) second.clj (println some-var) When I do this: bb first.clj second.clj in output: #'user/second , which not that I expected 😢 How get value from first file?

Bob B20:10:32

I believe that bb will take the first file as the file to execute, and the second file as an argument:

first.clj
(println *command-line-args*)

$ bb first.clj second.clj
(second.clj)
in short, I believe you can currently only execute one file (by specifying it on the command line) There's a change in master than will provide a --init option which sort of pre-loads the init file, so you could do something like:
$ bb --init first.clj -f second.clj
123
Alternatively, you could load first.clj from second.clj:
second.clj:
(load-file "first.clj")

(println some-var)

$ bb second.clj
123

Bob B20:10:58

and of course, you could put first.clj on your bb classpath in bb.edn and define a namespace in it, and then require that namespace from second.clj

Artem20:10:17

Thanks a lot!

borkdude20:10:10

Thanks for your replies @U013JFLRFS8!

denik19:10:19

is there a cross platform way to copy and retrieve data to the clipboard using babashka? and not just text, but also files etc. retrieval should be capable of the many mime types that are available

denik20:10:58

FWIW I use this in java to copy EDN as a string

(do
  (defn clipboard []
    (.getSystemClipboard (java.awt.Toolkit/getDefaultToolkit)))

  (defn clipboard-> []
    (try
      (.getTransferData (.getContents (clipboard) nil) (java.awt.datatransfer.DataFlavor/stringFlavor))
      (catch java.lang.NullPointerException e nil)))

  (defn ->clipboard
    ([x] (->clipboard true x))
    ([pretty? x]
     (let [text      (if (string? x)
                       x
                       (if pretty?
                         (with-out-str (clojure.pprint/pprint x))
                         (pr-str x)))
           selection (java.awt.datatransfer.StringSelection. text)]
       (.setContents (clipboard) selection selection))
     x)))

borkdude20:10:38

you could dispatch on (System/getProperty "os.name")

denik20:10:46

how would this work with files?

borkdude20:10:00

Good question, I don't know. Perhaps someone else here does? We could consider adding these classes to babashka so it will work like in Java, but because awt in my opinion stands for graphical stuff, and it's considered a bit old, I haven't done this.

denik20:10:44

especially curious how this would for non-text files

indy18:11:11

(-> (p/process ["cat" "something.html"])
    (p/process ["pbcopy"]))
This should work for text files (for mac).

denik18:11:36

thanks @UMPJRJU9E what about arbitrary files?

indy18:11:17

For macos, there might be a way by shelling out to osascript