From 32b3445f3b96ae1c177a026e0fc9726ce17bbf81 Mon Sep 17 00:00:00 2001 From: Arun Prakash Jana Date: Sun, 16 Jun 2019 18:56:11 +0530 Subject: [PATCH] Use case insensitive version sort to compare --- README.md | 8 +++----- nnn.1 | 4 ---- .../auto-completion/bash/nnn-completion.bash | 1 - scripts/auto-completion/fish/nnn.fish | 1 - scripts/auto-completion/zsh/_nnn | 1 - src/nnn.c | 20 +++++++++---------- 6 files changed, 12 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 4c603a09..44e37de9 100644 --- a/README.md +++ b/README.md @@ -78,9 +78,8 @@ It runs on Linux, macOS, Raspberry Pi, BSD, Cygwin, Linux subsystem for Windows - Bookmarks; pin and visit a directory - Familiar, easy shortcuts (arrows, ~, -, @) - Sorting - - Ordered pure numeric names by default (visit _/proc_) + - Case-insensitive version (_aka_ natural) sort - Sort by file name, modification time, size - - Version (_aka_ natural) sort - Search - Instant filtering with *search-as-you-type* - Regex and substring match @@ -199,8 +198,8 @@ Option completion scripts for Bash, Fish and Zsh can be found in respective subd #### Cmdline options ``` -usage: nnn [-b key] [-d] [-e] [-i] [-l] [-n] - [-p file] [-s] [-S] [-v] [-w] [-h] [PATH] +usage: nnn [-b key] [-d] [-e] [-i] [-l] [-p file] + [-s] [-S] [-v] [-w] [-h] [PATH] The missing terminal file manager for X. @@ -213,7 +212,6 @@ optional args: -e use exiftool for media info -i nav-as-you-type mode -l light mode - -n use version compare to sort -p file selection file (stdout if '-') -s string filters [default: regex] -S du mode diff --git a/nnn.1 b/nnn.1 index 9f628586..be88adb8 100644 --- a/nnn.1 +++ b/nnn.1 @@ -11,7 +11,6 @@ .Op Ar -e .Op Ar -i .Op Ar -l -.Op Ar -n .Op Ar -p file .Op Ar -s .Op Ar -S @@ -52,9 +51,6 @@ supports the following options: .Fl l start in light mode (fewer details) .Pp -.Fl n - use version compare to sort files -.Pp .Fl "p file" copy (or \fIpick\fR) selection to file, or stdout if file='-' .Pp diff --git a/scripts/auto-completion/bash/nnn-completion.bash b/scripts/auto-completion/bash/nnn-completion.bash index 25bbed08..4c81e770 100644 --- a/scripts/auto-completion/bash/nnn-completion.bash +++ b/scripts/auto-completion/bash/nnn-completion.bash @@ -17,7 +17,6 @@ _nnn () { -h -i -l - -n -p -s -S diff --git a/scripts/auto-completion/fish/nnn.fish b/scripts/auto-completion/fish/nnn.fish index 02f80246..c0a6b1f0 100644 --- a/scripts/auto-completion/fish/nnn.fish +++ b/scripts/auto-completion/fish/nnn.fish @@ -11,7 +11,6 @@ complete -c nnn -s e -d 'use exiftool instead of mediainfo' complete -c nnn -s h -d 'show this help and exit' complete -c nnn -s i -d 'start in navigate-as-you-type mode' complete -c nnn -s l -d 'start in light mode (fewer details)' -complete -c nnn -s n -d 'use version compare to sort files' complete -c nnn -s p -r -d 'copy selection to file' complete -c nnn -s s -d 'use substring match for filters' complete -c nnn -s S -d 'start in disk usage analyzer mode' diff --git a/scripts/auto-completion/zsh/_nnn b/scripts/auto-completion/zsh/_nnn index 20a313fc..17d1c1a3 100644 --- a/scripts/auto-completion/zsh/_nnn +++ b/scripts/auto-completion/zsh/_nnn @@ -15,7 +15,6 @@ args=( '(-h)-h[show this help and exit]' '(-i)-i[start in navigate-as-you-type mode]' '(-l)-l[start in light mode (fewer details)]' - '(-n)-n[use version compare to sort files]' '(-p)-p[copy selection to file]:file name' '(-s)-s[use substring match for filters]' '(-S)-S[start in disk usage analyzer mode]' diff --git a/src/nnn.c b/src/nnn.c index cc6541cd..d9db166a 100644 --- a/src/nnn.c +++ b/src/nnn.c @@ -1246,6 +1246,7 @@ static bool write_lastdir(const char *curpath) return ret; } +#if 0 static int digit_compare(const char *a, const char *b) { while (*a && *b && *a == *b) @@ -1333,6 +1334,7 @@ static int xstricmp(const char * const s1, const char * const s2) return strcoll(s1, s2); } +#endif /* * Version comparison @@ -1346,8 +1348,10 @@ static int xstricmp(const char * const s1, const char * const s2) * Compare S1 and S2 as strings holding indices/version numbers, * returning less than, equal to or greater than zero if S1 is less than, * equal to or greater than S2 (for more info, see the texinfo doc). + * + * Ignores case. */ -static int xstrverscmp(const char * const s1, const char * const s2) +static int xstrverscasecmp(const char * const s1, const char * const s2) { const uchar *p1 = (const uchar *)s1; const uchar *p2 = (const uchar *)s2; @@ -1413,8 +1417,6 @@ static int xstrverscmp(const char * const s1, const char * const s2) } } -static int (*cmpfn)(const char * const s1, const char * const s2) = &xstricmp; - /* Return the integer value of a char representing HEX */ static char xchartohex(char c) { @@ -1484,7 +1486,7 @@ static int entrycmp(const void *va, const void *vb) return -1; } - return cmpfn(pa->name, pb->name); + return xstrverscasecmp(pa->name, pb->name); } /* @@ -4289,8 +4291,8 @@ nochange: static void usage(void) { fprintf(stdout, - "%s: nnn [-b key] [-d] [-e] [-i] [-l] [-n]\n" - " [-p file] [-s] [-S] [-v] [-w] [-h] [PATH]\n\n" + "%s: nnn [-b key] [-d] [-e] [-i] [-l] [-p file]\n" + " [-s] [-S] [-v] [-w] [-h] [PATH]\n\n" "The missing terminal file manager for X.\n\n" "positional args:\n" " PATH start dir [default: current dir]\n\n" @@ -4300,7 +4302,6 @@ static void usage(void) " -e use exiftool for media info\n" " -i nav-as-you-type mode\n" " -l light mode\n" - " -n use version compare to sort\n" " -p file selection file (stdout if '-')\n" " -s string filters [default: regex]\n" " -S du mode\n" @@ -4434,7 +4435,7 @@ int main(int argc, char *argv[]) char *arg = NULL; int opt; - while ((opt = getopt(argc, argv, "Slib:denp:svwh")) != -1) { + while ((opt = getopt(argc, argv, "Slib:dep:svwh")) != -1) { switch (opt) { case 'S': cfg.blkorder = 1; @@ -4457,9 +4458,6 @@ int main(int argc, char *argv[]) case 'e': cfg.metaviewer = EXIFTOOL; break; - case 'n': - cmpfn = &xstrverscmp; - break; case 'p': cfg.picker = 1; if (optarg[0] == '-' && optarg[1] == '\0')