README.md | 6 ++++-- misc/auto-completion/bash/nnn-completion.bash | 1 + misc/auto-completion/fish/nnn.fish | 1 + misc/auto-completion/zsh/_nnn | 1 + nnn.1 | 4 ++++ src/nnn.c | 16 ++++++++++------ diff --git a/README.md b/README.md index 89288f2b13a7e227d9f7b23d05430e171075769d..d49af7369c63798480297468b9d13d8a1b0edf63 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,7 @@ - 4 contexts (_aka_ tabs/workspaces) - 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 - Search @@ -198,8 +199,8 @@ #### Cmdline options ``` -usage: nnn [-b key] [-d] [-e] [-i] [-l] [-p file] - [-s] [-S] [-v] [-w] [-h] [PATH] +usage: nnn [-b key] [-d] [-e] [-i] [-l] [-n] + [-p file] [-s] [-S] [-v] [-w] [-h] [PATH] The missing terminal file manager for X. @@ -212,6 +213,7 @@ -d show hidden files -e use exiftool for media info -i nav-as-you-type mode -l light mode + -n version sort -p file selection file (stdout if '-') -s string filters [default: regex] -S du mode diff --git a/misc/auto-completion/bash/nnn-completion.bash b/misc/auto-completion/bash/nnn-completion.bash index a0dcd30b787b098ecc3501dce80f819b393a629d..c30887a2a31cf7db53f5b8d325c390d89c65542f 100644 --- a/misc/auto-completion/bash/nnn-completion.bash +++ b/misc/auto-completion/bash/nnn-completion.bash @@ -17,6 +17,7 @@ -e -h -i -l + -n -p -s -S diff --git a/misc/auto-completion/fish/nnn.fish b/misc/auto-completion/fish/nnn.fish index c0a6b1f02d4710c2fe57182f153fab010e2b5563..02f80246dedf0f1922e1b8aadde8e63023acd733 100644 --- a/misc/auto-completion/fish/nnn.fish +++ b/misc/auto-completion/fish/nnn.fish @@ -11,6 +11,7 @@ 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/misc/auto-completion/zsh/_nnn b/misc/auto-completion/zsh/_nnn index 17d1c1a3c654f84be653764582fc549338f0cd4a..20a313fc209c8e221ea17d0d1ec8cc9e0680d358 100644 --- a/misc/auto-completion/zsh/_nnn +++ b/misc/auto-completion/zsh/_nnn @@ -15,6 +15,7 @@ '(-e)-e[use exiftool instead of mediainfo]' '(-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/nnn.1 b/nnn.1 index 85f4124d2e58e342731802056f967f8b21e7f4d7..aa400d6d85cc238bd1bdbd2fdad0fc729a267b10 100644 --- a/nnn.1 +++ b/nnn.1 @@ -11,6 +11,7 @@ .Op Ar -d .Op Ar -e .Op Ar -i .Op Ar -l +.Op Ar -n .Op Ar -p file .Op Ar -s .Op Ar -S @@ -50,6 +51,9 @@ start in navigate-as-you-type mode .Pp .Fl l start in light mode (fewer details) +.Pp +.Fl n + use case-insensitive version compare to sort files .Pp .Fl "p file" copy (or \fIpick\fR) selection to file, or stdout if file='-' diff --git a/src/nnn.c b/src/nnn.c index ce4dae22166b7e71e036c0d01ec4e84b7231d30d..acfefd264b2aca8a491c99dcbaa2e1207b2d5430 100644 --- a/src/nnn.c +++ b/src/nnn.c @@ -1274,7 +1274,6 @@ return ret; } -#if 0 static int digit_compare(const char *a, const char *b) { while (*a && *b && *a == *b) @@ -1362,7 +1361,6 @@ } return strcoll(s1, s2); } -#endif /* * Version comparison @@ -1445,6 +1443,8 @@ return state; } } +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) { @@ -1509,7 +1509,7 @@ if (pb->blocks < pa->blocks) return -1; } - return xstrverscasecmp(pa->name, pb->name); + return cmpfn(pa->name, pb->name); } /* @@ -4401,8 +4401,8 @@ static void usage(void) { fprintf(stdout, - "%s: nnn [-b key] [-d] [-e] [-i] [-l] [-p file]\n" - " [-s] [-S] [-v] [-w] [-h] [PATH]\n\n" + "%s: nnn [-b key] [-d] [-e] [-i] [-l] [-n]\n" + " [-p file] [-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" @@ -4412,6 +4412,7 @@ " -d show hidden files\n" " -e use exiftool for media info\n" " -i nav-as-you-type mode\n" " -l light mode\n" + " -n version sort\n" " -p file selection file (stdout if '-')\n" " -s string filters [default: regex]\n" " -S du mode\n" @@ -4545,7 +4546,7 @@ { char *arg = NULL; int opt; - while ((opt = getopt(argc, argv, "Slib:dep:svwh")) != -1) { + while ((opt = getopt(argc, argv, "Slib:denp:svwh")) != -1) { switch (opt) { case 'S': cfg.blkorder = 1; @@ -4567,6 +4568,9 @@ cfg.showhidden = 1; break; case 'e': cfg.metaviewer = EXIFTOOL; + break; + case 'n': + cmpfn = &xstrverscasecmp; break; case 'p': cfg.picker = 1;