From 30f43df559bd79e663919dd8d957b36303c7a8d8 Mon Sep 17 00:00:00 2001 From: Joseph Nuthalapati Date: Mon, 11 Jul 2022 14:29:09 +0530 Subject: [PATCH 1/5] Remove babashka preloads --- README.md | 20 +++++++++++++++++--- bb-aliases.nu | 3 --- bb-aliases.sh | 3 --- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 6abd22a..fb44973 100644 --- a/README.md +++ b/README.md @@ -32,13 +32,27 @@ Some tasks can also take arguments. 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. +## Shell aliases ``` sh -source bb-aliases.sh +# bash, zsh +source /path/to/babashka-scripts/bb-aliases.sh +alias task = bb --config ~/dev/babashka-scripts/bb.edn + +# nu +source /path/to/babashka-scripts/bb-aliases.nu +alias task = bb --config ~/dev/babashka-scripts/bb.edn +``` + +*Example:* To pull all the repositories in a directory, run + +``` sh +task gpa . ``` +There is a utility `bbe` to run tasks in the current working directory in `bb-aliases.sh`. + + *Example:* To pull all the repositories in a directory, run ``` sh diff --git a/bb-aliases.nu b/bb-aliases.nu index 7519e2d..ed6c67a 100644 --- a/bb-aliases.nu +++ b/bb-aliases.nu @@ -1,8 +1,5 @@ #!/usr/bin/env nu -let-env BABASHKA_PRELOADS = '(doseq [fil ["lib.clj" "utils.clj"]] (load-file (str (System/getProperty "user.home") "/dev/babashka-scripts/scripts/" fil)))' -let-env BABASHKA_PRELOADS = $env.BABASHKA_PRELOADS + " (require '[utils :refer :all])" - def bbe [task] { bb -e $"\(run-task-in-cwd \'($task)\)" } diff --git a/bb-aliases.sh b/bb-aliases.sh index 5e82ad8..70349bb 100644 --- a/bb-aliases.sh +++ b/bb-aliases.sh @@ -1,8 +1,5 @@ #!/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\")" } -- 2.43.0 From 0df5525be671d19747f8cccb8291f84d8b2ee932 Mon Sep 17 00:00:00 2001 From: Joseph Nuthalapati Date: Wed, 17 Aug 2022 17:26:51 +0530 Subject: [PATCH 2/5] git: Fix switching back to current branch in `gup` --- scripts/git.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/git.clj b/scripts/git.clj index b84cffb..aeacbbe 100755 --- a/scripts/git.clj +++ b/scripts/git.clj @@ -52,5 +52,5 @@ (map run-cmd '[["git" "checkout" "master"] ["git" "pull" "--rebase"] - ["git" "checkout" "-"] + ["git" "checkout" current-branch] ["git" "rebase" "master"]]))))) -- 2.43.0 From 181e14e7660c23ce20208b18dab7e021e7251e54 Mon Sep 17 00:00:00 2001 From: Joseph Nuthalapati Date: Wed, 19 Oct 2022 10:40:06 +0530 Subject: [PATCH 3/5] Add a diagnostic to check if `task` alias works --- bb.edn | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bb.edn b/bb.edn index 350ba7e..f285ffa 100644 --- a/bb.edn +++ b/bb.edn @@ -1,6 +1,9 @@ {:paths ["scripts"] :tasks - {gup {:requires ([git :refer [git-pull-rebase-branch]]) + {test {:doc "Test whether the 'task' alias is working." + :task (println "Yes, it's working!")} + + gup {:requires ([git :refer [git-pull-rebase-branch]]) :doc "Do a git pull and rebase branch with master in a given directory." :task (git-pull-rebase-branch (get (into [] *command-line-args*) 0))} -- 2.43.0 From e1035b9f7c0fbf7819409ca96eed64d92d3ef2d1 Mon Sep 17 00:00:00 2001 From: Joseph Nuthalapati Date: Sat, 26 Nov 2022 05:34:37 +0530 Subject: [PATCH 4/5] git: Fix function git-pull-rebase --- scripts/git.clj | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/scripts/git.clj b/scripts/git.clj index aeacbbe..370b315 100755 --- a/scripts/git.clj +++ b/scripts/git.clj @@ -6,8 +6,6 @@ ; Utilities for git operations -(def default-root ".") - (defn- has-git-repo [dir] (first (filter #(= ".git" %) @@ -19,8 +17,7 @@ (filter #(has-git-repo %) (filter #(.isDirectory %) (.listFiles (io/file root))))) -(defn- git-pull [dir] - (p/process ["git" "-C" dir "pull" "--rebase"])) +(defn- git-pull [dir] (p/process ["git" "-C" dir "pull" "--rebase"])) (defn git-pull-all "Runs `git-pull` on all the git repositories in a directory" @@ -34,23 +31,21 @@ p/check :out slurp) - pulls)] + pulls)] ;; Print corresponding directory name when pulling ;; Skip printing already up to date repos (doseq [[dir out] (filter #(not (.contains (second %) "is up to date.")) - (map vector dirs outputs))] + (map vector dirs outputs))] (println (str dir "\n" out))))) (defn git-pull-rebase-branch "Do git pull and rebase branch with master" [dir] + (run-cmd ["git" "pull" "--rebase"]) (let [current-branch (str/trim (run-cmd ["git" "branch" "--show-current"]))] - (git-pull dir) (when (not (contains? #{"master" "main"} current-branch)) (run! print (map run-cmd - '[["git" "checkout" "master"] - ["git" "pull" "--rebase"] - ["git" "checkout" current-branch] - ["git" "rebase" "master"]]))))) + [["git" "checkout" "master"] ["git" "pull" "--rebase"] + ["git" "checkout" current-branch] ["git" "rebase" "master"]]))))) -- 2.43.0 From 4dcdd4a9d879b2787550e849673e7e967878fd92 Mon Sep 17 00:00:00 2001 From: Joseph Nuthalapati Date: Sat, 26 Nov 2022 05:44:13 +0530 Subject: [PATCH 5/5] git: minor changes --- scripts/git.clj | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/scripts/git.clj b/scripts/git.clj index 370b315..e722c08 100755 --- a/scripts/git.clj +++ b/scripts/git.clj @@ -17,10 +17,13 @@ (filter #(has-git-repo %) (filter #(.isDirectory %) (.listFiles (io/file root))))) -(defn- git-pull [dir] (p/process ["git" "-C" dir "pull" "--rebase"])) +(defn- git-pull + "Do a git pull with rebase." + [dir] + (p/process ["git" "-C" dir "pull" "--rebase"])) (defn git-pull-all - "Runs `git-pull` on all the git repositories in a directory" + "Runs `git-pull` on all the git repositories in a directory." [root] (let [dirs (list-dirs root) pulls (->> root @@ -40,9 +43,9 @@ (defn git-pull-rebase-branch - "Do git pull and rebase branch with master" + "Do git pull and rebase branch with master." [dir] - (run-cmd ["git" "pull" "--rebase"]) + (git-pull dir) (let [current-branch (str/trim (run-cmd ["git" "branch" "--show-current"]))] (when (not (contains? #{"master" "main"} current-branch)) (run! print -- 2.43.0