pest.lisp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. ;; PROMPT_COMMAND='export PS1="$(pest)"'
  2. (defun config-parse (&optional path)
  3. (let ((config-path (if path path (concatenate 'string (uiop:getenv "HOME") "/.config/pest/config.toml"))))
  4. (if (probe-file config-path)
  5. (with-open-file (fh config-path :direction :input)
  6. (let ((file-content (with-output-to-string (out)
  7. (loop for line = (read-line fh nil)
  8. while line
  9. do (format out "~a~%" line)))))
  10. (clop:parse file-content)))
  11. (format T "~A: File not found" config-path))))
  12. (defvar *config* (config-parse "/home/swatson/Repos/cl-pest/config.toml"))
  13. ;; Colors
  14. (defvar *fg* (progn
  15. (if *config*
  16. (destructuring-bind (r g b) (subseq (assoc "fg" (cdr (assoc "colors" *config* :test #'equal)) :test #'equal) (- 4 3))
  17. (chlorophyll:create-rgb-color r g b))
  18. (chlorophyll:create-rgb-color 255 255 255))))
  19. (defvar *bg* (chlorophyll:create-rgb-color 0 0 0))
  20. (defvar *style* (chlorophyll:new-style
  21. :bold NIL
  22. :foreground *fg*
  23. :background *bg*))
  24. ;; Regex Scanners
  25. ;; TODO $HOME rendered as /home/user as opposed to ~
  26. (defvar *home-scan* (ppcre:create-scanner (concatenate 'string "^" (format NIL "~a" (user-homedir-pathname)))))
  27. (defun pwd ()
  28. (ppcre:regex-replace *home-scan* (uiop:getenv "PWD") "~/"))
  29. (defun main ()
  30. (setf *config* (config-parse "/home/swatson/Repos/cl-pest/config.toml"))
  31. (format T "~a λ " (chlorophyll:stylize *style* (pwd))))