Support opening in detail view mode

This commit is contained in:
Arun Prakash Jana 2017-04-01 10:48:18 +05:30
parent 8bbb752a79
commit 54a307767c
No known key found for this signature in database
GPG key ID: A75979F35C080412
3 changed files with 42 additions and 20 deletions

View file

@ -92,8 +92,10 @@ No plans of packaging at the time.
Start nnn (default: current directory): Start nnn (default: current directory):
$ nnn [path_to_dir] $ nnn [-d] [path_to_dir]
`>` indicates the currently selected entry.
-d: open in detail view mode
`>` indicates the currently selected entry in nnn.
### Keyboard shortcuts ### Keyboard shortcuts

9
nnn.1
View file

@ -6,6 +6,7 @@
.Nd free, fast, friendly file browser .Nd free, fast, friendly file browser
.Sh SYNOPSIS .Sh SYNOPSIS
.Nm nnn .Nm nnn
.Op Ar -d
.Op Ar dir .Op Ar dir
.Sh DESCRIPTION .Sh DESCRIPTION
.Nm .Nm
@ -69,6 +70,12 @@ Quit
.Pp .Pp
Backing up one directory level will set the cursor position at the Backing up one directory level will set the cursor position at the
directory you came out of. directory you came out of.
.Pp
.Nm
supports the following option:
.Pp
.Fl d
Open in detail view mode.
.Sh CONFIGURATION .Sh CONFIGURATION
.Nm .Nm
is configured by modifying is configured by modifying
@ -143,4 +150,4 @@ If you are using urxvt you might have to set backspacekey to DEC.
.An Dimitris Papastamos Aq Mt sin@2f30.org , .An Dimitris Papastamos Aq Mt sin@2f30.org ,
.An Arun Prakash Jana Aq Mt engineerarun@gmail.com . .An Arun Prakash Jana Aq Mt engineerarun@gmail.com .
.Sh HOME .Sh HOME
https://github.com/jarun/nnn .Em https://github.com/jarun/nnn

47
nnn.c
View file

@ -116,7 +116,6 @@ const char* size_units[] = {"B", "K", "M", "G", "T", "P", "E", "Z", "Y"};
* '------ * '------
*/ */
void (*printptr)(struct entry *ent, int active);
void printmsg(char *); void printmsg(char *);
void printwarn(void); void printwarn(void);
void printerr(int, char *); void printerr(int, char *);
@ -438,6 +437,8 @@ printent(struct entry *ent, int active)
printw("%s%s\n", active ? CURSR : EMPTY, ent->name); printw("%s%s\n", active ? CURSR : EMPTY, ent->name);
} }
void (*printptr)(struct entry *ent, int active) = &printent;
char* char*
coolsize(off_t size) coolsize(off_t size)
{ {
@ -933,9 +934,9 @@ nochange:
} }
void void
usage(char *argv0) usage(void)
{ {
fprintf(stderr, "usage: %s [dir]\n", argv0); fprintf(stderr, "usage: nnn [-d] [dir]\n");
exit(1); exit(1);
} }
@ -944,9 +945,7 @@ main(int argc, char *argv[])
{ {
char cwd[PATH_MAX], *ipath; char cwd[PATH_MAX], *ipath;
char *ifilter; char *ifilter;
int opt = 0;
if (argc > 2)
usage(argv[0]);
/* Confirm we are in a terminal */ /* Confirm we are in a terminal */
if (!isatty(0) || !isatty(1)) { if (!isatty(0) || !isatty(1)) {
@ -954,23 +953,37 @@ main(int argc, char *argv[])
exit(1); exit(1);
} }
if (getuid() == 0) if (argc > 3)
showhidden = 1; usage();
initfilter(showhidden, &ifilter);
printptr = &printent; while ((opt = getopt(argc, argv, "d")) != -1) {
switch (opt) {
if (argv[1] != NULL) { case 'd':
ipath = realpath(argv[1], cwd); /* Open in detail mode, if set */
if (!ipath) { showdetail = 1;
fprintf(stderr, "%s: no such dir\n", argv[1]); printptr = &printent_long;
exit(1); break;
default:
usage();
} }
} else { }
if (argc == optind) {
/* Start in the current directory */
ipath = getcwd(cwd, sizeof(cwd)); ipath = getcwd(cwd, sizeof(cwd));
if (ipath == NULL) if (ipath == NULL)
ipath = "/"; ipath = "/";
} else {
ipath = realpath(argv[optind], cwd);
if (!ipath) {
fprintf(stderr, "%s: no such dir\n", argv[optind]);
exit(1);
} }
}
if (getuid() == 0)
showhidden = 1;
initfilter(showhidden, &ifilter);
/* Get the default desktop mime opener, if set */ /* Get the default desktop mime opener, if set */
opener = getenv("NNN_OPENER"); opener = getenv("NNN_OPENER");