123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- ;; PROMPT_COMMAND='export PS1="$(pest)"'
- (defun config-parse (&optional path)
- (let ((config-path (if path path (concatenate 'string (uiop:getenv "HOME") "/.config/pest/config.toml"))))
- (if (probe-file config-path)
- (with-open-file (fh config-path :direction :input)
- (let ((file-content (with-output-to-string (out)
- (loop for line = (read-line fh nil)
- while line
- do (format out "~a~%" line)))))
- (clop:parse file-content))))))
-
- (defvar *config* NIL)
- ;; Colors
- (defvar *fg* NIL)
- (defvar *bg* NIL)
- (defvar *style* NIL)
- (defun reload-config ()
- (setf *config* (config-parse "~/Repos/cl-pest/config.toml"))
- (setf *fg* (if *config*
- (destructuring-bind (r g b) (subseq (assoc "fg" (cdr (assoc "colors" *config* :test #'equal)) :test #'equal) (- 4 3))
- (chlorophyll:create-rgb-color r g b))
- (chlorophyll:create-rgb-color 255 255 255)))
- (setf *bg* (if *config*
- (destructuring-bind (r g b) (subseq (assoc "bg" (cdr (assoc "colors" *config* :test #'equal)) :test #'equal) (- 4 3))
- (chlorophyll:create-rgb-color r g b))
- (chlorophyll:create-rgb-color 0 0 0)))
- (setf *style* (chlorophyll:new-style
- :bold NIL
- :foreground *fg*
- :background *bg*)))
- ;; Regex Scanners
- ;; TODO $HOME rendered as /home/user as opposed to ~
- (defvar *home-scan* (ppcre:create-scanner (concatenate 'string "^" (format NIL "~a" (user-homedir-pathname)))))
- (defun pwd ()
- (ppcre:regex-replace *home-scan* (uiop:getenv "PWD") "~/"))
- (defun main ()
- (reload-config)
- (format T "~a λ " (chlorophyll:stylize *style* (pwd))))
|