diff options
| author | eltrac <hi@eltr.ac> | 2026-07-04 11:38:47 +0800 |
|---|---|---|
| committer | eltrac <hi@eltr.ac> | 2026-07-04 11:43:28 +0800 |
| commit | 810e2c84060969e71dc2aa88a171040e17dbfd00 (patch) | |
| tree | d0b9c38ff976dcac83bc25ac35cedccaeb6b5239 | |
| parent | d1cea6216995bce18dbd87758d59637ec60d55bb (diff) | |
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
| -rw-r--r-- | main.clj | 28 |
1 files changed, 16 insertions, 12 deletions
@@ -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)))) |
