diff --git a/.local/share/common-lisp/source/ambrevar/file.lisp b/.local/share/common-lisp/source/ambrevar/file.lisp index 8111e033..304206f2 100644 --- a/.local/share/common-lisp/source/ambrevar/file.lisp +++ b/.local/share/common-lisp/source/ambrevar/file.lisp @@ -39,7 +39,24 @@ (cons #.(cons 'member (mapcar #'first osicat::+permissions+)))))) (:accessor-name-transformer #'name-identity)) -;; TODO: Customize `print-object'. +(export-always 'extension) +(defmethod extension ((file file)) + "Return the file extension. +If none, return the empty string unlike `pathname-type'." + (or (pathname-type (path file)) + "")) + +(export-always 'basename) +(defmethod basename ((file file)) + "Return the file basename (including the extension)." + (let ((last-separator (position (uiop:directory-separator-for-host) + (path file) :from-end t))) + (subseq (path file) + (1+ last-separator)))) + +(defmethod print-object ((file file) stream) + (print-unreadable-object (file stream :type t :identity t) + (write-string (basename file) stream))) (export-always 'file) (defun file (path) diff --git a/.local/share/common-lisp/source/ambrevar/shell.lisp b/.local/share/common-lisp/source/ambrevar/shell.lisp index 6f7fb773..227c1572 100644 --- a/.local/share/common-lisp/source/ambrevar/shell.lisp +++ b/.local/share/common-lisp/source/ambrevar/shell.lisp @@ -57,20 +57,6 @@ keeping the same cookie saves about 15% of time.") "Return the FILE description as per the `file' UNIX command." (magicffi:magic-file %magic-cookie-description file)) -(export-always 'file-extension) -(defun file-extension (file) - "Return the file extension. -If none, return the empty string unlike `pathname-type'." - (or (pathname-type file) - "")) - -(export-always 'file-basename) -(defun file-basename (file) - "Return the file basename (including the extension)." - (apply #'str:concat (pathname-name file) - (sera:and-let* ((ext (file-extension file))) - `("." ,ext)))) - (export-always 'match-extensions) (defun match-extensions (extension &rest more-extensions) "Return a predicate for files that match on of the provided extensions.