diff options
author | Colin Okay <okay@toyful.space> | 2022-03-04 14:17:42 -0600 |
---|---|---|
committer | Colin Okay <okay@toyful.space> | 2022-03-04 14:17:42 -0600 |
commit | 22ee290ca7a7b625fa9f1a1bb420a08fc94e51a7 (patch) | |
tree | 79f625f118c3094e7357d4077d958c33e933c461 /src | |
parent | c6fca94d84cf988a72df6074dc7a469b6b4ccad4 (diff) |
cleaned up merge-into-cache
Diffstat (limited to 'src')
-rw-r--r-- | src/lib.lisp | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/src/lib.lisp b/src/lib.lisp index b5256fe..ec44bca 100644 --- a/src/lib.lisp +++ b/src/lib.lisp @@ -76,19 +76,18 @@ (uiop:delete-file-if-exists (cached-oneliners-file))) (defun merge-into-cache (new-ols) - (if (uiop:file-exists-p (cached-oneliners-file)) - (let ((cached-ols (with-open-file (input (cached-oneliners-file)) (read input)))) - (with-open-file (out (cached-oneliners-file) :direction :output :if-exists :supersede) - (print - (nconc - new-ols - (remove-if - (lambda (old) - (find (getf old :id) new-ols :key (lambda (x) (getf x :id)))) - cached-ols)) - out))) - (with-open-file (out (cached-oneliners-file) :direction :output) - (print new-ols out)))) + (let* ((cached + (when (uiop:file-exists-p (cached-oneliners-file)) + (with-open-file (input (cached-oneliners-file)) (read input)))) + (updated + (append + new-ols + (loop for old in cached + for id = (getf old :id) + unless (find id new-ols :key (lambda (x) (getf x :id))) + collect old)))) + (with-open-file (output (cached-oneliners-file) :direction :output :if-exists :supersede) + (print updated output)))) ;;; UTILITIES (defun make-temp-file-name () @@ -115,7 +114,9 @@ the directories that appear in the value of that variable." (make-pathname :name name :directory directory)))) (defun tags-from-oneliner (oneliner) - (remove-if-not #'executable-on-system-p (ppcre:split " +" oneliner))) + (remove-duplicates + (remove-if-not #'executable-on-system-p (ppcre:split " +" oneliner)) + :test #'equal)) (defun prompt (prompt &key |