mirror of
https://github.com/jarun/nnn.git
synced 2024-11-28 05:41:31 +00:00
Option -T to change default sort order
This commit is contained in:
parent
fc8c5b46b3
commit
85379a703b
|
@ -31,6 +31,7 @@ _nnn ()
|
||||||
-s
|
-s
|
||||||
-S
|
-S
|
||||||
-t
|
-t
|
||||||
|
-T
|
||||||
-v
|
-v
|
||||||
-V
|
-V
|
||||||
-x
|
-x
|
||||||
|
@ -46,6 +47,9 @@ _nnn ()
|
||||||
COMPREPLY=( $(cd "$sessions_dir" && compgen -f -d -- "$cur") )
|
COMPREPLY=( $(cd "$sessions_dir" && compgen -f -d -- "$cur") )
|
||||||
elif [[ $prev == -t ]]; then
|
elif [[ $prev == -t ]]; then
|
||||||
return 1
|
return 1
|
||||||
|
elif [[ $prev == -T ]]; then
|
||||||
|
local keys=$(echo "a d e r s t v" | awk -v RS=' ' '{print $0}')
|
||||||
|
COMPREPLY=( $(compgen -W "$keys" -- "$cur") )
|
||||||
elif [[ $cur == -* ]]; then
|
elif [[ $cur == -* ]]; then
|
||||||
COMPREPLY=( $(compgen -W "${opts[*]}" -- "$cur") )
|
COMPREPLY=( $(compgen -W "${opts[*]}" -- "$cur") )
|
||||||
else
|
else
|
||||||
|
|
|
@ -30,6 +30,7 @@ complete -c nnn -s R -d 'disable rollover at edges'
|
||||||
complete -c nnn -s s -r -d 'load session by name' -x -a '@\t"last session" (ls $sessions_dir)'
|
complete -c nnn -s s -r -d 'load session by name' -x -a '@\t"last session" (ls $sessions_dir)'
|
||||||
complete -c nnn -s S -d 'start in disk usage analyzer mode'
|
complete -c nnn -s S -d 'start in disk usage analyzer mode'
|
||||||
complete -c nnn -s t -r -d 'timeout in seconds to lock'
|
complete -c nnn -s t -r -d 'timeout in seconds to lock'
|
||||||
|
complete -c nnn -s T -r -d 'a d e r s t v'
|
||||||
complete -c nnn -s v -d 'use version compare to sort files'
|
complete -c nnn -s v -d 'use version compare to sort files'
|
||||||
complete -c nnn -s V -d 'show program version and exit'
|
complete -c nnn -s V -d 'show program version and exit'
|
||||||
complete -c nnn -s x -d 'notis, sel to system clipboard'
|
complete -c nnn -s x -d 'notis, sel to system clipboard'
|
||||||
|
|
|
@ -28,6 +28,7 @@ args=(
|
||||||
'(-s)-s[load session]:session name'
|
'(-s)-s[load session]:session name'
|
||||||
'(-S)-S[start in disk usage analyzer mode]'
|
'(-S)-S[start in disk usage analyzer mode]'
|
||||||
'(-t)-t[timeout to lock]:seconds'
|
'(-t)-t[timeout to lock]:seconds'
|
||||||
|
'(-T)-T[a d e r s t v]:key'
|
||||||
'(-v)-v[use version compare to sort files]'
|
'(-v)-v[use version compare to sort files]'
|
||||||
'(-V)-V[show program version and exit]'
|
'(-V)-V[show program version and exit]'
|
||||||
'(-x)-x[notis, sel to system clipboard]'
|
'(-x)-x[notis, sel to system clipboard]'
|
||||||
|
|
5
nnn.1
5
nnn.1
|
@ -24,6 +24,7 @@
|
||||||
.Op Ar -s name
|
.Op Ar -s name
|
||||||
.Op Ar -S
|
.Op Ar -S
|
||||||
.Op Ar -t secs
|
.Op Ar -t secs
|
||||||
|
.Op Ar -T key
|
||||||
.Op Ar -v
|
.Op Ar -v
|
||||||
.Op Ar -V
|
.Op Ar -V
|
||||||
.Op Ar -x
|
.Op Ar -x
|
||||||
|
@ -110,6 +111,10 @@ supports the following options:
|
||||||
.Fl "t secs"
|
.Fl "t secs"
|
||||||
idle timeout in seconds to lock terminal
|
idle timeout in seconds to lock terminal
|
||||||
.Pp
|
.Pp
|
||||||
|
.Fl "T key"
|
||||||
|
sort order
|
||||||
|
keys: 'a'u / 'd'u / 'e'xtension / 'r'everse / 's'ize / 't'ime / 'v'ersion
|
||||||
|
.Pp
|
||||||
.Fl v
|
.Fl v
|
||||||
use case-insensitive version compare to sort files
|
use case-insensitive version compare to sort files
|
||||||
.Pp
|
.Pp
|
||||||
|
|
18
src/nnn.c
18
src/nnn.c
|
@ -4664,10 +4664,8 @@ static int handle_context_switch(enum action sel, char *newpath)
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool set_sort_flags(void)
|
static bool set_sort_flags(int r)
|
||||||
{
|
{
|
||||||
int r = get_input(messages[MSG_ORDER]);
|
|
||||||
|
|
||||||
switch (r) {
|
switch (r) {
|
||||||
case 'a': /* Apparent du */
|
case 'a': /* Apparent du */
|
||||||
cfg.apparentsz ^= 1;
|
cfg.apparentsz ^= 1;
|
||||||
|
@ -5559,7 +5557,7 @@ nochange:
|
||||||
cfg.blkorder = 0;
|
cfg.blkorder = 0;
|
||||||
continue;
|
continue;
|
||||||
default: /* SEL_SORT */
|
default: /* SEL_SORT */
|
||||||
if (!set_sort_flags()) {
|
if (!set_sort_flags(get_input(messages[MSG_ORDER]))) {
|
||||||
if (cfg.filtermode)
|
if (cfg.filtermode)
|
||||||
presel = FILTER;
|
presel = FILTER;
|
||||||
printwait(messages[MSG_INVALID_KEY], &presel);
|
printwait(messages[MSG_INVALID_KEY], &presel);
|
||||||
|
@ -6491,6 +6489,7 @@ static void usage(void)
|
||||||
" -s name load session by name\n"
|
" -s name load session by name\n"
|
||||||
" -S du mode\n"
|
" -S du mode\n"
|
||||||
" -t secs timeout to lock\n"
|
" -t secs timeout to lock\n"
|
||||||
|
" -T key sort order [a/d/e/r/s/t/v]\n"
|
||||||
" -v version sort\n"
|
" -v version sort\n"
|
||||||
" -V show version\n"
|
" -V show version\n"
|
||||||
" -x notis, sel to system clipboard\n"
|
" -x notis, sel to system clipboard\n"
|
||||||
|
@ -6626,7 +6625,7 @@ int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
char *arg = NULL;
|
char *arg = NULL;
|
||||||
char *session = NULL;
|
char *session = NULL;
|
||||||
int opt;
|
int opt, sort = 0;
|
||||||
#ifndef NOMOUSE
|
#ifndef NOMOUSE
|
||||||
mmask_t mask;
|
mmask_t mask;
|
||||||
char *middle_click_env = xgetenv(env_cfg[NNN_MCLICK], "\0");
|
char *middle_click_env = xgetenv(env_cfg[NNN_MCLICK], "\0");
|
||||||
|
@ -6640,7 +6639,7 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
while ((opt = (env_opts_id > 0
|
while ((opt = (env_opts_id > 0
|
||||||
? env_opts[--env_opts_id]
|
? env_opts[--env_opts_id]
|
||||||
: getopt(argc, argv, "aAb:cdeEgHKnop:QrRs:St:vVxh"))) != -1) {
|
: getopt(argc, argv, "aAb:cdeEgHKnop:QrRs:St:T:vVxh"))) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'a':
|
case 'a':
|
||||||
cfg.mtime = 0;
|
cfg.mtime = 0;
|
||||||
|
@ -6724,6 +6723,10 @@ int main(int argc, char *argv[])
|
||||||
if (env_opts_id < 0)
|
if (env_opts_id < 0)
|
||||||
idletimeout = atoi(optarg);
|
idletimeout = atoi(optarg);
|
||||||
break;
|
break;
|
||||||
|
case 'T':
|
||||||
|
if (env_opts_id < 0)
|
||||||
|
sort = optarg[0];
|
||||||
|
break;
|
||||||
case 'v':
|
case 'v':
|
||||||
namecmpfn = &xstrverscasecmp;
|
namecmpfn = &xstrverscasecmp;
|
||||||
break;
|
break;
|
||||||
|
@ -6938,6 +6941,9 @@ int main(int argc, char *argv[])
|
||||||
#endif
|
#endif
|
||||||
return _FAILURE;
|
return _FAILURE;
|
||||||
|
|
||||||
|
if (sort)
|
||||||
|
set_sort_flags(sort);
|
||||||
|
|
||||||
opt = browse(initpath, session);
|
opt = browse(initpath, session);
|
||||||
|
|
||||||
#ifndef NOMOUSE
|
#ifndef NOMOUSE
|
||||||
|
|
Loading…
Reference in a new issue