pest.lisp 1.6 KB

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