pebblisp/src/examples/pebblisp.pbl

1.8 KiB

(def black "")
(def red "")
(def green "")
(def yellow "")
(def blue "")
(def purple "")
(def cyan "")
(def white "")
 
(def bold "")
(def reset "")
 
(def esc (ch 27))
 
(def nl (ch 10))
 
(def fore (fn (action list)
"Apply the given action to each element in list." (
(map f list)
""
)))
 
(def first (fn (list) (at 0 list)))
 
(def up "..")
(def ~ (env "HOME"))
 
(def config (cat ~ "/.pebblisp.pbl"))
 
(def loadfile (fn (file-name)
"Read and evaluate the file with the given name." (
(eval (rf file-name))
)))
 
(def reloadConfig (fn () (loadfile config)))
 
(def string (fn (a) (cat "" a)))
 
(struct Alias (name value))
(def aliases (
(Alias "ls" "ls --color")
(Alias "alias" "(alias)")
(Alias "pbl" (cat (env "EDITOR") " ~/.pebblisp.pbl"))
(Alias "r" "(reloadConfig)")
))
 
(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)
 
" (prompt "")))ter (fn () (
))f commRunning () (
(sys "sleep 1")
(promptUpdater)
)))
 
(def preprocess (fn (text) (
(def matches (fil (fn (a) (= text a.name)) aliases))
(def match (first matches))
(if (iserr match) text match.value)
)))
 
(def hour (fn (ti) (
(def h (% ti.hour 12))
(if (= 0 h) 12 h)
)))
 
(def zero (fn (num) (cat (if (< num 10) "0" "") num)))
 
(def clock (fn (ti) (cat (hour ti) ":" (zero ti.minute) ":" (zero ti.sec))))
 
(def cleanDir (fn ()
"Get a string of the current directory" (
(def di (cwd))
(if (matches di (cat ~ "*"))
(cat "~" (substr (slen ~) 999 di))
di
)
)))
 
(def prompt (fn (a) (
(def ti (time))
(def d (cleanDir))
 
(cat nl
esc "]0; " d (ch 7)
bold red "[sage] " blue (clock ti) " " reset cyan d nl
bold green "pebblisp ~> " reset)
)))