Skip to content

Instantly share code, notes, and snippets.

@bakpakin
Created May 25, 2019 02:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bakpakin/1cbb2d86e346355695778b41d300f16f to your computer and use it in GitHub Desktop.
Save bakpakin/1cbb2d86e346355695778b41d300f16f to your computer and use it in GitHub Desktop.
janetsh rc
(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