Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jeroenvandijk
Created April 8, 2019 14:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeroenvandijk/33c51ab73480358ddad18277fc066717 to your computer and use it in GitHub Desktop.
Save jeroenvandijk/33c51ab73480358ddad18277fc066717 to your computer and use it in GitHub Desktop.
First experiment with closhrc
(defcmd git [& [dispatch :as args]]
(if (= dispatch "browse")
(let [{:keys [code stderr]
remote-url :stdout} (sh-value "git" "remote" "get-url" "origin")]
(if (zero? code)
(do (println "Opening" remote-url)
(sh "open" (clojure.string/trim remote-url)))
(println stderr)))
(eval `(sh "git" ~@args))))
(defcmd closhrc []
(load-file (str (getenv "HOME") "/.closhrc")))
(defn git-current-branch []
(let [{:keys [code stdout]} (sh-value "git" "branch")]
(when (zero? code)
(some (fn [line]
(when (.startsWith line "* ")
(clojure.string/trim (subs line 2 ))))
(clojure.string/split-lines stdout)))))
(defn current-dir []
(let [{dir :stdout} (sh-value "pwd")]
(last (clojure.string/split (clojure.string/trim dir) #"\/"))))
(defn closh-prompt []
(clojure.string/join " "
(remove
nil?
[" $"
(current-dir)
(when-let [b (git-current-branch)]
(str "git:(" b ")"))
" "])))
(println "CloshRC loaded")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment