From: Joseph Nuthalapati Date: Sun, 14 Feb 2021 16:44:31 +0000 (+0530) Subject: Add utils and shell aliases X-Git-Url: https://njoseph.me/gitweb/babashka-scripts.git/commitdiff_plain/00a9627659403ac2a910f8753cc2b1510384d6c3 Add utils and shell aliases Signed-off-by: Joseph Nuthalapati --- diff --git a/README.md b/README.md index f02c678..7fa3294 100644 --- a/README.md +++ b/README.md @@ -18,10 +18,23 @@ git clone https://njoseph.me/gitweb/babashka-scripts.git Add the following lines to your shell configuration file. ``` sh -export BABASHKA_PRELOADS='(load-file (str (System/getProperty "user.home") "/dev/babashka-scripts/lib.clj"))' +export BABASHKA_PRELOADS='(run! load-file (map #(str (System/getProperty "user.home") "/dev/babashka-scripts/" %) ["lib.clj" "utils.clj"]))' +export BABASHKA_PRELOADS=$BABASHKA_PRELOADS" (require '[utils :refer :all])" export PATH=$PATH:$HOME/dev/babashka-scripts ``` +Some useful aliases. + +``` sh +alias gup="bb -e '(git-pull-rebase-branch)'" +``` + ## Organization -`lib.clj` contains functions that the other scripts might use. It must be loaded first. +`lib.clj` contains functions that the other scripts might use. It must be loaded +first. + +`utils.clj` contains standalone utilities that can be executed directly. These are +convenient to use through shell aliases. + +The remaining Clojure files are executable scripts. diff --git a/utils.clj b/utils.clj new file mode 100644 index 0000000..38b9b74 --- /dev/null +++ b/utils.clj @@ -0,0 +1,16 @@ +(ns utils + (:require [lib :refer [run-cmd]] + [clojure.string :as str])) + +(defn git-pull-rebase-branch + "Do git pull and rebase branch with master" + [] + (let [current-branch (str/trim (run-cmd ["git" "branch" "--show-current"]))] + (print (run-cmd ["git" "pull" "--rebase"])) + (when (not (contains? #{"master" "main"} current-branch)) + (run! print + (map run-cmd + '[["git" "checkout" "master"] + ["git" "pull" "--rebase"] + ["git" "checkout" "-"] + ["git" "rebase" "master"]])))))