96 lines
2.2 KiB
Plaintext
96 lines
2.2 KiB
Plaintext
(def black "[30m")
|
||
(def red "[31m")
|
||
(def green "[32m")
|
||
(def yellow "[33m")
|
||
(def blue "[34m")
|
||
(def purple "[35m")
|
||
(def cyan "[36m")
|
||
(def white "[37m")
|
||
|
||
(def esc (ch 27))
|
||
|
||
(def bold "[1m")
|
||
(def reset "[0m")
|
||
(def ~ (env "HOME"))
|
||
|
||
(def config (cat ~ "/.pebblisp.pbl"))
|
||
|
||
(def reloadConfig (fn () (loadfile config)))
|
||
|
||
(def editConfig (fn () (
|
||
(sys (cat (env "EDITOR") " " config))
|
||
(reloadConfig)
|
||
)))
|
||
|
||
(def forthFile "/home/sagevaillancourt/projects/pebblisp/src/examples/forbble2.pbl")
|
||
(struct Alias (name value))
|
||
(def aliases (
|
||
(Alias "ls" "ls --color")
|
||
(Alias "vimc" "vim ~/.vimrc")
|
||
(Alias "alias" "(alias)")
|
||
(Alias "pbl" "(editConfig)")
|
||
(Alias "tags" "ctags --exclude=node_modules -f newtags -R . && mv newtags tags")
|
||
(Alias "r" "(reloadConfig)")
|
||
(Alias "cd ~" (cat "cd " ~))
|
||
(Alias "rename" "git commit --amend --author 'Sage Vaillancourt <sagev9000@tutanota.com>'")
|
||
(Alias "plf" "(loadfile forthFile)")
|
||
(Alias "sudo" "echo -e '\e[1;31m' && sudo")
|
||
))
|
||
|
||
(def alias (fn ()
|
||
"Get a string that lists all current aliases." (
|
||
(reduce (map (fn (a) (cat nl a.name " -> " a.value)) aliases) cat "")
|
||
)))
|
||
|
||
(def commRunning F)
|
||
|
||
(def saveCurPos "[s")
|
||
(def loadCurPos "[u")
|
||
|
||
(def promptUpdater (fn () (
|
||
(if commRunning () (
|
||
(prn (cat saveCurPos " [2A[1G" (prompt "") loadCurPos))
|
||
))
|
||
(sys "sleep 1")
|
||
(promptUpdater)
|
||
)))
|
||
|
||
(def preprocess (fn (text) (
|
||
(def alias-matches (fil (fn (a) (startsWith text a.name)) aliases))
|
||
(def match (first alias-matches))
|
||
(if (iserr match) text
|
||
(cat match.value (substr (slen match.name) 999 text))
|
||
)
|
||
)))
|
||
|
||
(def hour (fn (ti)
|
||
"Get the hour 1-12 of the given Time struct." (
|
||
(def h (% ti.hour 12))
|
||
(if (= 0 h) 12 h)
|
||
)))
|
||
|
||
(def zero (fn (num) (cat (if (< num 10) "0" "") num)))
|
||
|
||
(def clock (fn (ti)
|
||
"Get a simple H:MM:SS time string"
|
||
(cat (hour ti) ":" (zero ti.minute) ":" (zero ti.sec))
|
||
))
|
||
|
||
(def cleanDir (fn ()
|
||
"Get a string of the current directory" (
|
||
(def directory (cwd))
|
||
(if (matches directory (cat ~ "*"))
|
||
(cat "~" (substr (slen ~) 999 directory))
|
||
directory
|
||
)
|
||
)))
|
||
|
||
(def prompt (fn (a) (
|
||
(def d (cleanDir))
|
||
|
||
(cat nl
|
||
esc "]0; " d (ch 7)
|
||
bold red "[sage] " blue (clock (time)) " " reset cyan d nl
|
||
bold green "pebblisp ~> " reset)
|
||
)))
|