pebblisp/src/examples/pebblisp.pbl

2.2 KiB

(def black "")
(def red "")
(def green "")
(def yellow "")
(def blue "")
(def purple "")
(def cyan "")
(def white "")
 
(def esc (ch 27))
 
(def bold "")
(def reset "")
(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")
 
" (prompt "") loadCurPos))(
))f commRunning () (
(sys "sleep 1")eCurPos "
(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)
)))