Fork me on GitHub

Is there any bash expert in the house that can look at this PR?


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


That would be (process/process ["xterm" "-e" ".."] {:inherit true})


yea works 🙂


*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.


I'm on windows 10 with babashka v0.7.3


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.


I get:

$ bb test


$ bb test.clj


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


you can require babashka.tasks :refer [shell] in files too


Oh, woa. Thanks, I hadn't noticed the (require '[babashka.tasks :as tasks]) in section.


We should probably document that then. Feel free to send a PR


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.


but it may not be apparent that you can use these in scripts as well


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 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 Right 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 ( "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. I'm also wondering what belongs in the bb.edn file. I initially assumed "everything" but now I'm thinking "as little as possible".


You get the current file with

(def current-file *file*)


yeah, you can put the code supporting your tasks in a file


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*)
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


or if you change to :paths ["."] then it works with what you currently have


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


I'll be back in 30 minutes


No worries. No rush.


add :requires ([current-file]) in your :tasks map


Oh, right! Sorry, my first issue was including bb in the name and then I forgot to require it with this example. Thanks!

Michaël Salihi19:01:57

Thanks for the sharing @U04V15CAJ 👍:skin-tone-3:


And you for making this :)

😉 1