From 03d4c62e61ea0e7ece11b14302fbbc0588df5ef0 Mon Sep 17 00:00:00 2001 From: Thomas Lindop Date: Wed, 28 May 2025 10:58:55 +0100 Subject: [PATCH] >> add shell compatible runeset > add flag to select runeset > update documentation --- main.go | 43 +++++++++++++++++++++++++++++++++++++++---- man.md | 13 ++++++++++--- 2 files changed, 49 insertions(+), 7 deletions(-) diff --git a/main.go b/main.go index 5a021d9..c5b78a2 100644 --- a/main.go +++ b/main.go @@ -89,14 +89,23 @@ var FAT_RUNESET = runeset{ } var POSIX_PORTABLE_RUNESET = runeset{ - { 0x2d, 0x2d }, - { 0x2e, 0x2e }, + { 0x2d, 0x2e }, { 0x5f, 0x5f }, { 0x30, 0x39 }, { 0x41, 0x5a }, { 0x61, 0x7a }, } +var SHELL_RUNESET = runeset{ + { 0x25, 0x25 }, + { 0x2d, 0x2e }, + { 0x30, 0x39 }, + { 0x41, 0x5a }, + { 0x5f, 0x5f }, + { 0x61, 0x7a }, + { 0xc0, MAX_CODE_POINT }, +} + /// MAIN FUNCTIONS /** * Compares paths so that all files come before the directories that contain @@ -269,12 +278,26 @@ func parseCLIArgs(args []string) (context, error) { result.Strategy = args[index] case "-p", "--portable": result.Rset = POSIX_PORTABLE_RUNESET + case "-e", "--valid-set": + index++ + switch args[index] { + case "fat": + result.Rset = FAT_RUNESET + case "posix": + result.Rset = POSIX_PORTABLE_RUNESET + case "shell": + result.Rset = SHELL_RUNESET + default: + return result, errors.New( + "Invalid character set! Please choose one of fat,posix,shell", + ) + } case "-c", "--replace": index++ target, subs, ok := strings.Cut(args[index], ":") if !ok { return result, errors.New(fmt.Sprintf( - "Incorrect syntax (<<%s>>) for replacement: please use '{TARGET}:{REPLACEMNT1},{REPLACEMNT2},...'", + "Incorrect syntax (<<%s>>) for replacement: please use '{TARGET}:{REPLACEMENT1},{REPLACEMENT2},...'", args[index], )) } @@ -322,13 +345,25 @@ func printHelp() { (?,\,*,etc.) are removed. Options: - -s,--strategy + -s,--strategy remove|represent + What to do with bad characters; either replace with a representation or + remove -h,--help + Show this message -v,--version + Show version -r,--recurse DIRECTORY + Recursively search for files in DIRECTORY with bad characters -n,--dry-run + Do not rename anything, just print what would be done + -t,--truncate LENGTH + Truncate all filenames to at most LENGTH bytes + -e,--valid-set fat|posix|shell + Select a set of characters to limit filenames to. -p,--portable + Alias for "--valid-set posix" + See man page for more details `); } diff --git a/man.md b/man.md index 02b11c2..22d87b7 100644 --- a/man.md +++ b/man.md @@ -32,10 +32,17 @@ includes DIRECTORY itself. Causes Owl to just print a representation of what would be done without actually renaming any files. +### -e,\-\-valid-set fat|posix|shell +Select which characters are considered "invalid" or "bad". Options are: + - fat: Characters which are valid in file names on FAT file systems. This + is the default. + - posix: The POSIX Portable Filename Character Set `A-Za-z0-9.-_` + - shell: Characters that *should* not need to be quoted when used in a + shell, i.e. all characters apart from control characters, whitespace, and + most punctuation. + ### -p,\-\-portable -Restrict characters to ones in the POSIX Portable Filename Character Set -(see , section 3.265) -instead of FAT compatible ones. +An alias for "\-\-valid-set posix". ### -v, \-\-version Show version information.