pest.lisp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. (defvar *config* NIL)
  12. ;; Colors
  13. (defvar *fg* NIL)
  14. (defvar *bg* NIL)
  15. (defvar *style* NIL)
  16. (defun reload-config ()
  17. (setf *config* (config-parse "~/Repos/cl-pest/config.toml"))
  18. (setf *fg* (if *config*
  19. (destructuring-bind (r g b) (subseq (assoc "fg" (cdr (assoc "colors" *config* :test #'equal)) :test #'equal) (- 4 3))
  20. (chlorophyll:create-rgb-color r g b))
  21. (chlorophyll:create-rgb-color 255 255 255)))
  22. (setf *bg* (if *config*
  23. (destructuring-bind (r g b) (subseq (assoc "bg" (cdr (assoc "colors" *config* :test #'equal)) :test #'equal) (- 4 3))
  24. (chlorophyll:create-rgb-color r g b))
  25. (chlorophyll:create-rgb-color 0 0 0)))
  26. (setf *style* (chlorophyll:new-style
  27. :bold NIL
  28. :foreground *fg*
  29. :background *bg*)))
  30. ;; Regex Scanners
  31. ;; TODO $HOME rendered as /home/user as opposed to ~
  32. (defvar *home-scan* (ppcre:create-scanner (concatenate 'string "^" (format NIL "~a" (user-homedir-pathname)))))
  33. (defun pwd ()
  34. (ppcre:regex-replace *home-scan* (uiop:getenv "PWD") "~/"))
  35. (defun main ()
  36. (reload-config)
  37. (format T "~a λ " (chlorophyll:stylize *style* (pwd))))