Option -a to use file access time

This commit is contained in:
Arun Prakash Jana 2019-08-30 20:55:23 +05:30
parent 3f40980dd0
commit ec873ab4fa
No known key found for this signature in database
GPG key ID: A75979F35C080412
6 changed files with 23 additions and 9 deletions

View file

@ -74,7 +74,7 @@ Visit the **[Wiki](https://github.com/jarun/nnn/wiki)** for operational concepts
- Sorting - Sorting
- Ordered pure numeric names by default (visit _/proc_) - Ordered pure numeric names by default (visit _/proc_)
- Case-insensitive version (_aka_ natural) sort - Case-insensitive version (_aka_ natural) sort
- Sort by file name, modification time, size, file extension - By file name, modification/access time, size, extension
- Search - Search
- Instant filtering with *search-as-you-type* - Instant filtering with *search-as-you-type*
- Regex and substring match - Regex and substring match
@ -202,8 +202,8 @@ Option completion scripts for Bash, Fish and Zsh can be found in respective subd
#### Cmdline options #### Cmdline options
``` ```
usage: nnn [-b key] [-d] [-H] [-i] [-n] [-o] [-p file] usage: nnn [-a] [-b key] [-d] [-H] [-i] [-n] [-o]
[-r] [-s] [-S] [-t] [-v] [-h] [PATH] [-p file] [-r] [-s] [-S] [-t] [-v] [-h] [PATH]
The missing terminal file manager for X. The missing terminal file manager for X.
@ -211,6 +211,7 @@ positional args:
PATH start dir [default: current dir] PATH start dir [default: current dir]
optional args: optional args:
-a use access time
-b key open bookmark key -b key open bookmark key
-d detail mode -d detail mode
-H show hidden files -H show hidden files

View file

@ -11,6 +11,7 @@ _nnn () {
local cur=$2 prev=$3 local cur=$2 prev=$3
local -a opts local -a opts
opts=( opts=(
-a
-b -b
-d -d
-H -H

View file

@ -5,6 +5,7 @@
# Arun Prakash Jana <engineerarun@gmail.com> # Arun Prakash Jana <engineerarun@gmail.com>
# #
complete -c nnn -s a -d 'use access time'
complete -c nnn -s b -r -d 'bookmark key to open' complete -c nnn -s b -r -d 'bookmark key to open'
complete -c nnn -s d -d 'start in detail mode' complete -c nnn -s d -d 'start in detail mode'
complete -c nnn -s H -d 'show hidden files' complete -c nnn -s H -d 'show hidden files'

View file

@ -9,6 +9,7 @@
setopt localoptions noshwordsplit noksharrays setopt localoptions noshwordsplit noksharrays
local -a args local -a args
args=( args=(
'(-a)-a[use access time]'
'(-b)-b[bookmark key to open]:key char' '(-b)-b[bookmark key to open]:key char'
'(-d)-d[start in detail mode]' '(-d)-d[start in detail mode]'
'(-H)-H[show hidden files]' '(-H)-H[show hidden files]'

4
nnn.1
View file

@ -6,6 +6,7 @@
.Nd the missing terminal file manager for X .Nd the missing terminal file manager for X
.Sh SYNOPSIS .Sh SYNOPSIS
.Nm .Nm
.Op Ar -a
.Op Ar -b key .Op Ar -b key
.Op Ar -d .Op Ar -d
.Op Ar -H .Op Ar -H
@ -36,6 +37,9 @@ to see the list of keybinds.
.Nm .Nm
supports the following options: supports the following options:
.Pp .Pp
.Fl a
use access time for all operations (default: modification time)
.Pp
.Fl "b key" .Fl "b key"
specify bookmark key to open specify bookmark key to open
.Pp .Pp

View file

@ -215,7 +215,7 @@ typedef struct {
uint copymode : 1; /* Set when copying files */ uint copymode : 1; /* Set when copying files */
uint showdetail : 1; /* Clear to show fewer file info */ uint showdetail : 1; /* Clear to show fewer file info */
uint ctxactive : 1; /* Context active or not */ uint ctxactive : 1; /* Context active or not */
uint reserved : 8; uint reserved : 7;
/* The following settings are global */ /* The following settings are global */
uint curctx : 2; /* Current context number */ uint curctx : 2; /* Current context number */
uint dircolor : 1; /* Current status of dir color */ uint dircolor : 1; /* Current status of dir color */
@ -229,6 +229,7 @@ typedef struct {
uint runctx : 2; /* The context in which plugin is to be run */ uint runctx : 2; /* The context in which plugin is to be run */
uint filter_re : 1; /* Use regex filters */ uint filter_re : 1; /* Use regex filters */
uint trash : 1; /* Move removed files to trash */ uint trash : 1; /* Move removed files to trash */
uint mtime : 1; /* Use modification time (else access time) */
} settings; } settings;
/* Contexts or workspaces */ /* Contexts or workspaces */
@ -268,6 +269,7 @@ static settings cfg = {
0, /* runctx */ 0, /* runctx */
1, /* filter_re */ 1, /* filter_re */
0, /* trash */ 0, /* trash */
1, /* mtime */
}; };
static context g_ctx[CTX_MAX] __attribute__ ((aligned)); static context g_ctx[CTX_MAX] __attribute__ ((aligned));
@ -3056,7 +3058,7 @@ static int dentfill(char *path, struct entry **dents)
off += dentp->nlen; off += dentp->nlen;
/* Copy other fields */ /* Copy other fields */
dentp->t = sb.st_mtime; dentp->t = cfg.mtime ? sb.st_mtime : sb.st_atime;
if (dp->d_type == DT_LNK && !flags) { /* Do not add sizes for links */ if (dp->d_type == DT_LNK && !flags) { /* Do not add sizes for links */
dentp->mode = (sb.st_mode & ~S_IFMT) | S_IFLNK; dentp->mode = (sb.st_mode & ~S_IFMT) | S_IFLNK;
dentp->size = 0; dentp->size = 0;
@ -3283,7 +3285,7 @@ static void redraw(char *path)
char sort[] = "\0 "; char sort[] = "\0 ";
if (cfg.mtimeorder) if (cfg.mtimeorder)
sort[0] = 'T'; sort[0] = cfg.mtime ? 'T' : 'A';
else if (cfg.sizeorder) else if (cfg.sizeorder)
sort[0] = 'S'; sort[0] = 'S';
else if (cfg.extnorder) else if (cfg.extnorder)
@ -4536,12 +4538,13 @@ nochange:
static void usage(void) static void usage(void)
{ {
fprintf(stdout, fprintf(stdout,
"%s: nnn [-b key] [-d] [-H] [-i] [-n] [-o] [-p file]\n" "%s: nnn [-a] [-b key] [-d] [-H] [-i] [-n] [-o]\n"
" [-r] [-s] [-S] [-t] [-v] [-h] [PATH]\n\n" " [-p file] [-r] [-s] [-S] [-t] [-v] [-h] [PATH]\n\n"
"The missing terminal file manager for X.\n\n" "The missing terminal file manager for X.\n\n"
"positional args:\n" "positional args:\n"
" PATH start dir [default: current dir]\n\n" " PATH start dir [default: current dir]\n\n"
"optional args:\n" "optional args:\n"
" -a use access time\n"
" -b key open bookmark key\n" " -b key open bookmark key\n"
" -d detail mode\n" " -d detail mode\n"
" -H show hidden files\n" " -H show hidden files\n"
@ -4688,7 +4691,7 @@ int main(int argc, char *argv[])
bool progress = FALSE; bool progress = FALSE;
#endif #endif
while ((opt = getopt(argc, argv, "HSib:dnop:rstvh")) != -1) { while ((opt = getopt(argc, argv, "HSiab:dnop:rstvh")) != -1) {
switch (opt) { switch (opt) {
case 'S': case 'S':
cfg.blkorder = 1; cfg.blkorder = 1;
@ -4701,6 +4704,9 @@ int main(int argc, char *argv[])
case 'i': case 'i':
cfg.filtermode = 1; cfg.filtermode = 1;
break; break;
case 'a':
cfg.mtime = 0;
break;
case 'b': case 'b':
arg = optarg; arg = optarg;
break; break;