From 2d4b565f777b0edf6ee0737d354b2e8a2ee802e6 Mon Sep 17 00:00:00 2001 From: Rostislav Svoboda Date: Thu, 8 Feb 2024 13:59:38 +0100 Subject: [PATCH] Add --filepath multi-parameter: an alternative to --exact-filepaths --- main.rkt | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/main.rkt b/main.rkt index 106a581..c24f241 100644 --- a/main.rkt +++ b/main.rkt @@ -102,6 +102,7 @@ (define pattern-param (make-parameter "")) (define filepaths-param (make-parameter "")) + (define filepath-param (make-parameter (list))) (define case-sensitive "i") (define case-insensitive "-i") @@ -135,12 +136,17 @@ racket main.rkt -e ./main.rkt -p \"[eeeee]\" racket main.rkt -e ./main.rkt -p \"[eéèêë]\" racket main.rkt -e \"/home/bost/der/search-notes/main.rkt /home/bost/der/search-notes/README.md\" -p subdir " + #:multi + [("-f" "--filepath") + FILEPATH + "Exact filepath on the file system." + (filepath-param (cons FILEPATH (filepath-param)))] #:once-each ;; see also .spacemacs definition [("-e" "--exact-filepaths") FILEPATHS - "List of exact filepaths on the file system." + "String of exact filepaths on the file system, separated by spaces." (filepaths-param FILEPATHS)] [("-c" "--case-sensitivity-params") CS (case-sensitivity-params-help-text) @@ -245,7 +251,7 @@ racket main.rkt -e \"/home/bost/der/search-notes/main.rkt /home/bost/der/search- regexp-split-match relevant-file-strings-joined)) (printf "\n\n"))) relevant-file-strings))) - ;; (lambda (files) (printf "1. files:\n~a\n" files) files) + ;; (lambda (files) (printf "3. files:\n~a\n" files) files) (curry map (lambda (f) (let ((strs (call-with-input-file f @@ -270,6 +276,25 @@ racket main.rkt -e \"/home/bost/der/search-notes/main.rkt /home/bost/der/search- (if (empty? strs) (list f) (list f (string-join strs "\n\n")))))) + ;; (lambda (files) (printf "2. files:\n~a\n" files) files) + remove-duplicates + ;; environment variable in the path is expanded by the shell + (curry map (compose + ;; - Unix and Mac OS: convert by decoding path’s byte-string + ;; encoding using the current locale + ;; - Windows: convert by using UTF-8 + ;; path->string + + ;; convert by using a UTF-8 encoding + some-system-path->string + + ;; handle up- or same-directory indicators + simple-form-path + + ;; convert tilda '~' + expand-user-path)) + ;; (lambda (files) (printf "1. files:\n~a\n" files) files) + (curry append (filepath-param)) ;; (lambda (files) (printf "0. files:\n~a\n" files) files) string-split) (filepaths-param)))