]> njoseph.me Git - babashka-scripts.git/commitdiff
git: minor changes master
authorJoseph Nuthalapati <njoseph@riseup.net>
Sat, 26 Nov 2022 00:14:13 +0000 (05:44 +0530)
committerJoseph Nuthalapati <njoseph@riseup.net>
Sat, 26 Nov 2022 00:14:13 +0000 (05:44 +0530)
README.md
bb-aliases.nu
bb-aliases.sh
bb.edn
scripts/git.clj

index 6abd22a08ba1dbb8a11483453df3288bc0e7e3b2..fb44973ae690978a2a20ce84cdc8b4885381e0fc 100644 (file)
--- 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
index 7519e2d794f60104db2a0118b2cc59edbe2c314d..ed6c67a9b70559ed807bdb6dc8ad95bd609b71ac 100644 (file)
@@ -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)\)"
 }
index 5e82ad8ed1a00daac07cad1525387e8d5072ee11..70349bbc9321da845c2763c6e727396b1b7a4589 100644 (file)
@@ -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\")"
 }
diff --git a/bb.edn b/bb.edn
index 350ba7e3ffb595bbe4f47a6adcd402f1c51db761..f285ffa6cf57a68892f9bc1d6c0aec968bf71618 100644 (file)
--- 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))}
 
index b84cffbb395faf22700316da481e3145d4df1bb6..e722c08322476b6162b0663d69d74129b1b0036f 100755 (executable)
@@ -6,8 +6,6 @@
 
 ; Utilities for git operations
 
-(def default-root ".")
-
 (defn- has-git-repo
   [dir]
   (first (filter #(= ".git" %)
   (filter #(has-git-repo %)
     (filter #(.isDirectory %) (.listFiles (io/file root)))))
 
-(defn- git-pull [dir]
+(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
                            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"
+  "Do git pull and rebase branch with master."
   [dir]
+  (git-pull dir)
   (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" "-"]
-                   ["git" "rebase" "master"]])))))
+              [["git" "checkout" "master"] ["git" "pull" "--rebase"]
+               ["git" "checkout" current-branch] ["git" "rebase" "master"]])))))