Fork me on GitHub

;; babashka v1.1.172
(babashka.process/shell {:continue true} "fo")
;; error=2, No such file or directory..
I'm confused why it throws an err.


Don't know, I guess you could debug :)


It seems process builder throws when the program doesn't exist:

   :message "Cannot run program \"fo\": error=2, No such file or directory"
   :at [java.lang.ProcessBuilder start "" 1128]}
   :message "error=2, No such file or directory"
   :at [java.lang.ProcessImpl forkAndExec "" -2]}]


How do you guys answer "can I shell out to a program" from babashka scripts? I want to warn users and exit early if they need to install something in order to use my script. In Go, I've used I skimmed the API docs for babashka/process and babashka/fs, but I didn't spot what I was looking for. > LookPath searches for an executable named file in the directories named by the PATH environment variable. If file contains a slash, it is tried directly and the PATH is not consulted. Otherwise, on success, the result is an absolute path.


@U3X7174KS shell should already do what you want


can shell let me know whether there is an fzf binary on the user's path before invoking fzf? (I can confirm that using shell to invoke fzf works perfectly when I have fzf on my system)


yes, there is the fs/which function for this

💯 2

Ah, perfect. fs/which was exactly what I was looking for. Thank you! 🙌

👍 8

Very quick and dirty hack to solve "I want to install some library I've used before, but I don't remember the coordinates". 1. Make sure you have babaskha, fzf and bbin installed 2. bbin install io.github.teodorlu/neil-quickadd --latest-sha 3. neil-quickadd rescan (just need to run this once) 4. neil-quickadd 5. Pick a library 6. neil dep add is executed to add the library. Only works for ZSH for now. And there's very little validation. But it's 80 lines total -- all the heavy lifting is done by bbin, babashka/fs, babashka/process and babashka/neil. This works by parsing ~/.zsh_history, which may be a bad idea.

🎉 2

feel free to steal / modify / make your own versions if this appeals to you 🙂


@U3X7174KS is another tool that parses shell history (zsh and bash), maybe it helps to make it more portable :)

💯 2

Thanks! I know for a fact that I don't handle multiline shell commands correctly right now.


Would it be valuable to have paths from the in babashka/fs? E.g. (fs/xdg-config-home) ;;=> #object[sun.nio.fs.UnixPath 0x3c79d6e5 "/Users/gert/.config"] (as well as fs/xdg-data-home , fs/xdg-cache-home and fs/xdg-state-home ).


Hmm maybe. Aren't these just environment variable lookups normally?


with env-vars you can override them - so value of XDG_CONFIG_HOME if present or ~/.config by default.


right, this makes sense :)


issue + PR welcome


Thx, will do!


PR coming later this weekend