Created
May 25, 2019 02:10
-
-
Save bakpakin/1cbb2d86e346355695778b41d300f16f to your computer and use it in GitHub Desktop.
janetsh rc
This file contains 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
(import shlib) | |
(defn ansi | |
"Take a string made by concatenating xs and colorize it for an ANSI terminal." | |
[code & xs] | |
(string "\e[" code "m" ;xs "\e[0m")) | |
(defn cmd | |
"Run a quick command and strip trailing newline." | |
[s] | |
(let [f (file/popen s) | |
r (file/read f :all)] | |
(file/close f) | |
(string/slice r 0 -2))) | |
(defn my-prompt | |
[p] | |
(let [wd (os/cwd) | |
home (os/getenv "HOME") | |
user (os/getenv "USER") | |
host (cmd "uname -n") | |
fwd (if (string/has-prefix? home wd) | |
(string/replace home "~" wd) | |
wd)] | |
(string (ansi "31;1" user "@" host) | |
":" | |
(ansi "34;1" fwd) | |
":" | |
(ansi "34;1" (parser/state p)) | |
"$ "))) | |
(set *get-prompt* my-prompt) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment