From 66364757cbb0f829838573b642ccdacce9a1a726 Mon Sep 17 00:00:00 2001 From: Joseph Nuthalapati Date: Sun, 9 Jan 2022 18:08:58 +0530 Subject: [PATCH] Add utility to run tasks in the current directory --- README.md | 13 +++++++++++++ bb-aliases.sh | 8 ++++++++ scripts/utils.clj | 12 +++++++++++- 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 bb-aliases.sh diff --git a/README.md b/README.md index 8cbda08..6abd22a 100644 --- 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 index 0000000..5e82ad8 --- /dev/null +++ b/bb-aliases.sh @@ -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\")" +} diff --git a/scripts/utils.clj b/scripts/utils.clj index 8ea7664..1de2099 100644 --- a/scripts/utils.clj +++ b/scripts/utils.clj @@ -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. @@ -13,3 +14,12 @@ (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)))) -- 2.43.0