From 810e2c84060969e71dc2aa88a171040e17dbfd00 Mon Sep 17 00:00:00 2001 From: eltrac Date: Sat, 4 Jul 2026 11:38:47 +0800 Subject: if it's already on target branch, don't switch branch rename variable branch-name to target-branch don't switch branch after if it's the same branch format code --- main.clj | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/main.clj b/main.clj index 0c671f3..7992cd9 100644 --- a/main.clj +++ b/main.clj @@ -4,7 +4,7 @@ '[babashka.fs :as fs] '[clojure.edn :as edn]) -(def default-config +(def default-config {:editor-command "nvim" :editor-config "/Users/eltrac/.config/nvim/" :default-branch "master"}) @@ -25,16 +25,20 @@ (spit path default-config)) path) - -(let [[branch-name & args] *command-line-args* +(let [[target-branch & args] *command-line-args* config (-> (config-path) init-config slurp edn/read-string) - current-branch (or - (shell {:dir (:editor-config config) - :out :string} - "git branch --show-current") - (:default-branch config))] - (shell {:dir (:editor-config config)} - (str "git switch " branch-name)) - (shell (str (:editor-command config) " " (apply str args))) + current-branch (or + (shell {:dir (:editor-config config) + :out :string} + "git branch --show-current") + (:default-branch config))] + ;; switch to target branch + (when-not (= current-branch target-branch) + (shell {:dir (:editor-config config)} + (str "git switch " target-branch))) + ;; then use editor + (shell (str (:editor-command config) " " (apply str args))) + ;; lastly, swtich back + (when-not (= current-branch target-branch) (shell {:dir (:editor-config config)} - (str "git switch " current-branch))) + (str "git switch " current-branch)))) -- cgit v1.2.3