diff options
| -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)))) |
