This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-11-15
Channels
- # announcements (1)
- # asami (29)
- # babashka (31)
- # beginners (48)
- # calva (39)
- # cljsrn (4)
- # clojure (56)
- # clojure-dev (51)
- # clojure-doc (3)
- # clojure-europe (40)
- # clojure-gamedev (13)
- # clojure-italy (22)
- # clojure-nl (3)
- # clojure-uk (5)
- # cursive (9)
- # datomic (184)
- # events (7)
- # fulcro (8)
- # graalvm (2)
- # jobs (1)
- # malli (6)
- # meander (1)
- # nrepl (5)
- # off-topic (10)
- # pathom (9)
- # polylith (33)
- # portal (2)
- # re-frame (7)
- # reagent (12)
- # releases (3)
- # remote-jobs (3)
- # reveal (27)
- # shadow-cljs (34)
- # sql (1)
- # vim (7)
- # xtdb (62)
I'm using (clojure.java.shell/sh "open" filename)
to open a newly created file, but that's probably not OS independent. I can't find anything similar in babashka.fs
or
... what is the best way to open a file via the filesystem from a babashka script?
It's the end of a script. It outputs a html file (that I don't want to serve) . And the output is too much to print user friendly in the terminal.
too bad it will 'duplicate' filename ... it's configured in the script and now I have to type it in the terminal ... but I guess the history completion will help here.
well it's up to you, you can also still do the dispatch on OS, or only call open when open is available
A cross-platform option is to use explorer
instead of open
on Windows and xdg-open
on Linux. Each of these opens a file in the app that is bound to that file type, e.g. the default browser for HTML files.
I have the following in a bb.edn file:
{:tasks {aaaa {:doc "testing"
:task (shell "cd build")}}}
when I execute
bb aaaa
I get the following error
----- Error --------------------------------------------------------------------
Type: java.io.IOException
Message: Cannot run program "cd": error=2, No such file or directory
Location: 21:11
Does "shell" support changing directory?@hairfire cd
is often a bash / zsh / etc built-in, not a real program. also shell
doesn't really invoke a default shell, it just calls an executable program either on your PATH or via an absolute/relative path
The JVM environment doesn't allow changing working directory. A workaround for this is often to define a dynamic var or atom which contains the current working directory and then use that in functions that should take that into consideration.
If you want to invoke a program in another directory, you can do that with shell
like this:
(shell {:dir "some-other-directory"} "my-program")
I know this is a few days late, but I’m confused by this statement. e.g. If I’m using bash, then:
~ pgearon$ cat op
#!/bin/bash
cd tmp
~ pgearon$ ./op
~ pgearon$ pwd
/Users/pgearon
~ pgearon$
The cd
command only affects the process that it’s in, which is the equivalent of bb
using the {:dir "other-dir"}
option.
I’m curious as to the bash
code that you were hoping to replace with bb
?I have heard that comment from other people as well. I haven't personally missed it a lot. There are other ways to accomplish the same task.
But babashka is bound to what GraalVM / JVM allows you to do. For example #nbb which is based on Node.js, does allow it.
At the moment, I wanted to change into a directory, execute 'lein uberjar', then use the generated jar in my bb script.
@hairfire how I would do that is:
(def project-dir "project")
(shell {:dir project-dir} "lein uberjar")
(fs/file project-dir "target" "foo-standalone.jar")
see e.g.:
https://github.com/clj-kondo/clj-kondo.lsp/blob/b1097c318c0d51b3c7e45192005c0f7d8765cd68/bb.edn#L37