]> Sergey Matveev's repositories - nnn.git/commitdiff
Support opening in detail view mode
authorArun Prakash Jana <engineerarun@gmail.com>
Sat, 1 Apr 2017 05:18:18 +0000 (10:48 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Sat, 1 Apr 2017 05:18:18 +0000 (10:48 +0530)
README.md
nnn.1
nnn.c

index a366436f0b4dc361a75fbd6d817282ebdb345897..8be8d230f24b458bb6815a5dd3733f65126b2188 100644 (file)
--- a/README.md
+++ b/README.md
@@ -92,8 +92,10 @@ No plans of packaging at the time.
 
 Start nnn (default: current directory):
 
-    $ nnn [path_to_dir]
-`>` indicates the currently selected entry.
+    $ nnn [-d] [path_to_dir]
+
+    -d: open in detail view mode
+`>` indicates the currently selected entry in nnn.
 
 ### Keyboard shortcuts
 
diff --git a/nnn.1 b/nnn.1
index 632298ba62ccfc500eb046ae1ae206405bcb96a9..136ac58444f24195af316925f00a37f5aee9f2ee 100644 (file)
--- a/nnn.1
+++ b/nnn.1
@@ -6,6 +6,7 @@
 .Nd free, fast, friendly file browser
 .Sh SYNOPSIS
 .Nm nnn
+.Op Ar -d
 .Op Ar dir
 .Sh DESCRIPTION
 .Nm
@@ -69,6 +70,12 @@ Quit
 .Pp
 Backing up one directory level will set the cursor position at the
 directory you came out of.
+.Pp
+.Nm
+supports the following option:
+.Pp
+.Fl d
+        Open in detail view mode.
 .Sh CONFIGURATION
 .Nm
 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 Arun Prakash Jana Aq Mt engineerarun@gmail.com .
 .Sh HOME
-https://github.com/jarun/nnn
+.Em https://github.com/jarun/nnn
diff --git a/nnn.c b/nnn.c
index 9b42219a600f8884b03b39fc4e65a195a92aea4a..743ceb3cb84f8b6d2ca99458bca6fddb8e4b531a 100644 (file)
--- a/nnn.c
+++ b/nnn.c
@@ -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 printwarn(void);
 void printerr(int, char *);
@@ -438,6 +437,8 @@ printent(struct entry *ent, int active)
                printw("%s%s\n", active ? CURSR : EMPTY, ent->name);
 }
 
+void (*printptr)(struct entry *ent, int active) = &printent;
+
 char*
 coolsize(off_t size)
 {
@@ -933,9 +934,9 @@ nochange:
 }
 
 void
-usage(char *argv0)
+usage(void)
 {
-       fprintf(stderr, "usage: %s [dir]\n", argv0);
+       fprintf(stderr, "usage: nnn [-d] [dir]\n");
        exit(1);
 }
 
@@ -944,9 +945,7 @@ main(int argc, char *argv[])
 {
        char cwd[PATH_MAX], *ipath;
        char *ifilter;
-
-       if (argc > 2)
-               usage(argv[0]);
+       int opt = 0;
 
        /* Confirm we are in a terminal */
        if (!isatty(0) || !isatty(1)) {
@@ -954,24 +953,38 @@ main(int argc, char *argv[])
                exit(1);
        }
 
-       if (getuid() == 0)
-               showhidden = 1;
-       initfilter(showhidden, &ifilter);
-
-       printptr = &printent;
+       if (argc > 3)
+               usage();
 
-       if (argv[1] != NULL) {
-               ipath = realpath(argv[1], cwd);
-               if (!ipath) {
-                       fprintf(stderr, "%s: no such dir\n", argv[1]);
-                       exit(1);
+       while ((opt = getopt(argc, argv, "d")) != -1) {
+               switch (opt) {
+               case 'd':
+                       /* Open in detail mode, if set */
+                       showdetail = 1;
+                       printptr = &printent_long;
+                       break;
+               default:
+                       usage();
                }
-       } else {
+       }
+
+       if (argc == optind) {
+               /* Start in the current directory */
                ipath = getcwd(cwd, sizeof(cwd));
                if (ipath == NULL)
                        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 */
        opener = getenv("NNN_OPENER");