Pārlūkot izejas kodu

Added handling for no config file

Simon Watson 1 gadu atpakaļ
vecāks
revīzija
4baca4bc57
2 mainītis faili ar 34 papildinājumiem un 8 dzēšanām
  1. 0 4
      config.toml
  2. 34 4
      pest.lisp

+ 0 - 4
config.toml

@@ -1,7 +1,3 @@
-[colors]
-fg = [255, 255, 255]
-bg = [0, 0, 0]
-
 [git]
 display_head = true
 display_branch = true

+ 34 - 4
pest.lisp

@@ -5,15 +5,45 @@
   "Shortcut function over :test #'equal for working with TOML alists"
   (cdr (assoc key alist :test #'equal)))
 
+(defun find-config ()
+  (let ((config-paths (list
+		       (concatenate 'string (uiop:getenv "HOME") "/.config/pest/config.toml")
+		       "/etc/pest/config.toml"
+		       (concatenate 'string (uiop:getenv "PWD") "./config"))))
+    (loop for path-str in config-paths
+	  do (if (probe-file path-str)
+		 (return-from find-config path-str)))))
+
 (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)
+  (let ((config-path (if path path (find-config))))
+    (if 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))))))
+			     (clop:parse file-content)))
+	(clop:parse "
+[git]
+display_head = false
+display_branch = false
+git_prefix = \"\"
+[git.colors]
+fg = [0, 120, 50]
+bg = [0, 0, 0]
+
+[prompt]
+display_user = false
+user_suffix = \"\"
+display_hostname = false
+hostname_suffix = \"\"
+display_pwd = true
+pwd_suffix = \"\"
+prompt_char = \" λ \"
+[prompt.colors]
+fg = [255, 255, 255]
+bg = [0, 0, 0]
+"))))
 			   
 (defvar *config* NIL)
 
@@ -100,7 +130,7 @@
 	
 
 (defun reload-config ()
-  (setf *config* (config-parse "~/Repos/cl-pest/config.toml"))
+  (setf *config* (config-parse))
   (setf *prompt-style* (make-style *config* "prompt"))
   (if (check-git-enabled *config*)
       (setf *git-style* (make-style *config* "git"))))