]> njoseph.me Git - babashka-scripts.git/commitdiff
Add utility to run tasks in the current directory
authorJoseph Nuthalapati <njoseph@riseup.net>
Sun, 9 Jan 2022 12:38:58 +0000 (18:08 +0530)
committerJoseph Nuthalapati <njoseph@riseup.net>
Sun, 9 Jan 2022 12:38:58 +0000 (18:08 +0530)
README.md
bb-aliases.sh [new file with mode: 0644]
scripts/utils.clj

index 8cbda0831e1edd27e853e754bedc9070dd765329..6abd22a08ba1dbb8a11483453df3288bc0e7e3b2 100644 (file)
--- a/README.md
+++ b/README.md
@@ -31,3 +31,16 @@ Some tasks can also take arguments.
 ``` sh
 bb ebook-to-audiobook the-great-gatsby.epub
 ```
+
+There are a utility file that makes running the tasks easier. Load it up first.  
+You can also add the following line with the absolute path to the file in your "~/.profile" file.
+
+``` sh
+source bb-aliases.sh
+```
+
+*Example:* To pull all the repositories in a directory, run
+
+``` sh
+bbe gpa
+```
diff --git a/bb-aliases.sh b/bb-aliases.sh
new file mode 100644 (file)
index 0000000..5e82ad8
--- /dev/null
@@ -0,0 +1,8 @@
+#!/usr/bin/env bash
+
+export BABASHKA_PRELOADS='(doseq [fil ["lib.clj" "utils.clj"]] (load-file (str (System/getProperty "user.home") "/dev/babashka-scripts/scripts/" fil)))'
+export BABASHKA_PRELOADS=$BABASHKA_PRELOADS"  (require '[utils :refer :all])"
+
+bbe() {
+    bb -e "(run-task-in-cwd \"$1\")"
+}
index 8ea7664bdc8ade10fcb140a1b5dfea46f922bff7..1de2099b182374b786a7c26e727d34ae16387797 100644 (file)
@@ -1,5 +1,6 @@
 (ns utils
-  (:require [lib :refer [run-cmd]]))
+  (:require [lib :refer [expand-home run-cmd]]
+            [babashka.process :refer [process]]))
 
 (defn run-seq
   "Run a sequence of shell commands on a sequence of arguments.
   (doseq [argument arguments
           command commands]
     (println (run-cmd [command argument]))))
+
+(defn run-task-in-cwd
+  "Run a bb task from this repository in the current working directory."
+  [task]
+  (let [current-dir (System/getenv "PWD")
+        babashka-scripts-dir (expand-home "~/dev/babashka-scripts/")]
+    (print (-> (process ["bb" task current-dir] {:dir babashka-scripts-dir})
+               :out
+               slurp))))