Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save andrewchambers/9627b028b76fe376655052bbd13a1939 to your computer and use it in GitHub Desktop.
Save andrewchambers/9627b028b76fe376655052bbd13a1939 to your computer and use it in GitHub Desktop.
.janetsh.rc
(set *hist-file* (first (sh/expand "~/.janetsh.hist")))
(def tc
{
# The wrapping \x01 ... \x02 tell readline the surrounded string has zero length.
# Without it we get strange artifacts in the string history.
:bold "\x01\x1b[1m\x02"
:none "\x01\x1b[0m\x02"
})
(set *get-prompt*
(fn [p]
(var cwd (os/cwd))
(var home (os/getenv "HOME"))
(var who "<unknown>")
(var where "<unknown>")
(var end "$")
(def pstate (parser/state p))
(when (not (empty? pstate))
(set end (string pstate "..")))
(try
(do
(set who (sh/$$_ whoami))
(set where (sh/$$_ hostname)))
([e] nil))
(when (string/has-prefix? home cwd)
(set cwd (string "~" (string/slice cwd (length home)))))
(string (tc :bold)
"[" who "@" where ":" cwd "] " end " "
(tc :none))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment