This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-01-21
Channels
- # announcements (26)
- # aws (1)
- # babashka (40)
- # beginners (36)
- # calva (9)
- # cider (38)
- # clara (5)
- # clj-commons (4)
- # clj-kondo (29)
- # cljs-dev (8)
- # cljsrn (2)
- # clojars (12)
- # clojure (151)
- # clojure-europe (16)
- # clojure-gamedev (1)
- # clojure-nl (2)
- # clojure-uk (7)
- # clojurescript (2)
- # copenhagen-clojurians (2)
- # datalevin (18)
- # fulcro (7)
- # graphql (7)
- # gratitude (9)
- # helix (2)
- # honeysql (3)
- # introduce-yourself (1)
- # jobs (1)
- # lsp (13)
- # malli (10)
- # nextjournal (2)
- # off-topic (13)
- # pathom (1)
- # pedestal (2)
- # portal (4)
- # remote-jobs (1)
- # ring-swagger (1)
- # shadow-cljs (21)
- # specter (1)
- # testing (2)
- # tools-build (6)
- # vim (2)
- # xtdb (5)
Is there any bash expert in the house that can look at this PR? https://github.com/babashka/book/pull/46#issuecomment-1017932480
@U06FS3DLH maybe? 😛
I don't use bash interactively (only for scripting things I should be using bb for :rolling_on_the_floor_laughing:), so I'm not very familiar with how the autocomplete stuff works. Looks cool though! Maybe I'll try implementing it for fish shell! 😎
hi I wonder how I can start a proc so that it runs in the background and puts it output into the repl output. Alternatively it pops a terminal or sth; I tried (process/process ["xterm" "-e" ".."])
but its fiddely
*file*
isn't defined for my task. {:tasks {test (println *file*)}}
running bb test
prints <expr>
If I put (println *file*)
in a test.clj
file and run bb -f test.clj
then it doesn't print anything. Perhaps there's more to this issue.
Also, why can I use shell
in a task but I have to require sh
for a script? Initially, I approached writing tasks as if I were writing a script but now I'm wondering what's different.
note that when you do (println *file*)
in a function, then it's not bound to the file of that function anymore. file is only bound when the file is evaluated, so you have to capture it on the top level
Oh, woa. Thanks, I hadn't noticed the (require '[babashka.tasks :as tasks])
in https://book.babashka.org/#_shell section.
Oh, it's documented here: > The `babashka.tasks` namespace exposes the following functions: `run`, `shell`, `clojure` and `current-task`. They are implicitly imported, thus available without a namespace prefix.
Yea, I think I was treating those as magic since I didn't know where they came from. I connected cider to bb --nrepl-server
so that I could eval stuff but I didn't think I could get shell
so I was using clojure.java.shell/sh
for testing and then changing it to shell
for the task.
I also tried pretty hard to nest tasks even though nothing suggests that it's supported.
I found the code for tasks. I didn't know that *file*
comes from clojure.core. I thought it was coming from babashka. Regarding bb -f test.clj
not printing anything, I was actually just overlooking it. It was printing correctly but I thought I was looking at the command prompt which shows the current directory.
I was missing the distinction between running a script and running tasks. e.g. I thought I could use *file*
to get the https://book.babashka.org/#_current_file_path. Right https://book.babashka.org/#_parsing_command_line_argumentsthat section it has instructions on how to use *command-line-args*
which does actually work in a task.
How should I get the current file? (prn (slurp (:out (shell "pwd"))))
gives me ""
(prn (clojure.string/trim (:out (clojure.java.shell/sh "pwd"))))
gives me "/c/Users/.../project-folder"
That can be good enough. I just have to convert it to a path like "C:/Users/.../project-folder"
(fs/directory? "C:/Users/richie/Documents")
is true
(fs/directory? "/c/Users/richie/Documents")
is false
I was just browsing through the recent history and I found a comment mirroring my thoughts. https://clojurians.slack.com/archives/CLX41ASCS/p1642523166058600 I'm also wondering what belongs in the bb.edn file. I initially assumed "everything" but now I'm thinking "as little as possible".
and then keep the bb.edn as small as possible with only the task names and a few requires
my convention lately is to store the script files in $project/bb
and then add :paths ["bb"]
to bb.edn
Sorry, I still don't have it working.
{:paths ["bb"]
:tasks {test {:task (println (ns-map 'bb.current-file))}}}
and bb/current_file.clj
(ns bb.current-file)
(def current-file *file*)
gives
C:\Users\richie\Documents\my-project>bb test
----- Error --------------------------------------------------------------------
Type: java.lang.Exception
Message: No namespace: bb.current-file found
Location: 20:11
The namespace should be (ns current-file)
. bb isn't part of the dir structure that is on the paths
Hmm, I removed "bb" from my bb.edn and from bb/current_file.clj but I just get the same error No namespace: current-file found
I'll try on a mac as a sanity check.
➜ test tree
.
├── bb
│ └── current_file.clj
└── bb.edn
1 directory, 2 files
➜ test cat bb.edn
{:paths ["bb"]
:tasks { test (println current-file/current-file)}}
➜ test cat bb/current_file.clj
(ns current-file)
(def current-file *file*)
➜ test bb test
----- Error --------------------------------------------------------------------
Type: clojure.lang.ExceptionInfo
Message: Could not resolve symbol: current-file/current-file
Location: <expr>:23:10
Phase: analysis
----- Context ------------------------------------------------------------------
19: nil
20: (def test (binding [
21: babashka.tasks/*task* '{:name test, :task (println current-file/current-file)}]
22: nil
23: (println current-file/current-file))) test
^--- Could not resolve symbol: current-file/current-file
Oh, right! Sorry, my first issue was including bb in the name and then I forgot to require it with this example. Thanks!
HTMX + babashka project by @admin055 https://twitter.com/borkdude/status/1484557699996164105
Thanks for the sharing @U04V15CAJ 👍:skin-tone-3: