Created
April 8, 2019 14:03
-
-
Save jeroenvandijk/33c51ab73480358ddad18277fc066717 to your computer and use it in GitHub Desktop.
First experiment with closhrc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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