From 9b999105546b39172ce70269d8441a02e01c2b08 Mon Sep 17 00:00:00 2001 From: eltrac Date: Sat, 4 Jul 2026 11:49:58 +0800 Subject: set up project bb.edn --- bb.edn | 1 + main.clj | 44 -------------------------------------------- vimulti.clj | 44 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 44 deletions(-) create mode 100644 bb.edn delete mode 100644 main.clj create mode 100644 vimulti.clj diff --git a/bb.edn b/bb.edn new file mode 100644 index 0000000..5837a2a --- /dev/null +++ b/bb.edn @@ -0,0 +1 @@ +{:paths ["."]} diff --git a/main.clj b/main.clj deleted file mode 100644 index 7992cd9..0000000 --- a/main.clj +++ /dev/null @@ -1,44 +0,0 @@ -#!/usr/bin/env bb - -(require '[babashka.tasks :refer [shell]] - '[babashka.fs :as fs] - '[clojure.edn :as edn]) - -(def default-config - {:editor-command "nvim" - :editor-config "/Users/eltrac/.config/nvim/" - :default-branch "master"}) - -(defn- config-path [] - (let [env-vimnulti-config (System/getenv "VIMULTI_CONFIG") - env-xdg-config-home (System/getenv "XDG_CONFIG_HOME") - config-filename "config.edn"] - (or env-vimnulti-config - (if env-xdg-config-home - (str env-xdg-config-home "/vimulti/" config-filename) - config-filename)))) - -(defn- init-config [path] - (when-not (fs/exists? path) - (fs/create-dirs (fs/parent path)) - (fs/create-file path) - (spit path default-config)) - path) - -(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))] - ;; 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)))) diff --git a/vimulti.clj b/vimulti.clj new file mode 100644 index 0000000..7992cd9 --- /dev/null +++ b/vimulti.clj @@ -0,0 +1,44 @@ +#!/usr/bin/env bb + +(require '[babashka.tasks :refer [shell]] + '[babashka.fs :as fs] + '[clojure.edn :as edn]) + +(def default-config + {:editor-command "nvim" + :editor-config "/Users/eltrac/.config/nvim/" + :default-branch "master"}) + +(defn- config-path [] + (let [env-vimnulti-config (System/getenv "VIMULTI_CONFIG") + env-xdg-config-home (System/getenv "XDG_CONFIG_HOME") + config-filename "config.edn"] + (or env-vimnulti-config + (if env-xdg-config-home + (str env-xdg-config-home "/vimulti/" config-filename) + config-filename)))) + +(defn- init-config [path] + (when-not (fs/exists? path) + (fs/create-dirs (fs/parent path)) + (fs/create-file path) + (spit path default-config)) + path) + +(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))] + ;; 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)))) -- cgit v1.2.3