]> Sergey Matveev's repositories - nnn.git/commitdiff
Support batch file rename in vidir
authorArun Prakash Jana <engineerarun@gmail.com>
Sat, 24 Feb 2018 14:16:58 +0000 (19:46 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Sat, 24 Feb 2018 14:16:58 +0000 (19:46 +0530)
CHANGELOG
README.md
nnn.1
nnn.c
nnn.h

index ae2c98cf4d0e8a7ba42e238e5c5d03e30de1ca4f..b12401dad1853e845316fa26dd120041b72c31da 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -5,6 +5,7 @@ What's in?
 - Copy multiple file paths
 - Copy file paths when X is unavailable
 - Optionally quote individual file paths with single quotes on copy
+- Batch rename files in vidir from [moreutils](https://joeyh.name/code/moreutils/)
 - Use ISO 8601 date format in file details
 - New/changed/remapped shortcuts:
   - <kbd>^B</kbd> - show bookmark prompt (replaces <kbd>b</kbd>)
index 5d06900c03f136fb9050736336f30781c7d9dbda..6cebcf3f0a0e17929f43a7a5034ae60689d0ade6 100644 (file)
--- a/README.md
+++ b/README.md
@@ -109,6 +109,7 @@ Have fun with it! PRs are welcome. Check out [#1](https://github.com/jarun/nnn/i
   - Sort by file name, modification time, size
 - Convenience
   - Create, rename files and directories
+  - Batch rename current directory entries in vidir (from moreutils)
   - Spawn SHELL (fallback sh) in the current directory
   - Copy absolute file paths with/without X (*easy* shell integration)
   - Change directory at exit (*easy* shell integration)
@@ -238,6 +239,7 @@ optional arguments:
               M | Full media info
               n | Create new
              ^R | Rename entry
+              R | Rename dir entries
               s | Toggle sort by size
           S, ^J | Toggle du mode
               t | Toggle sort by mtime
@@ -303,6 +305,7 @@ The following abbreviations are used in the detail view:
       export NNN_DE_FILE_MANAGER=nautilus
 - [mediainfo](https://mediaarea.net/en/MediaInfo) (or [exiftool](https://sno.phy.queensu.ca/~phil/exiftool/), if specified) is required to view media information
 - [atool](http://www.nongnu.org/atool/) is required to list and extract archives
+- vidir from [moreutils](https://joeyh.name/code/moreutils/) is used to batch rename entries in current directory
 
 #### Help
 
diff --git a/nnn.1 b/nnn.1
index d895828d8d3007076ef4ac7cd7f8240b3d538225..9308f770fd6c8bfb03f0556b913436f3141a161c 100644 (file)
--- a/nnn.1
+++ b/nnn.1
@@ -82,6 +82,8 @@ Show full media info
 Create a new file or directory
 .It Ic ^R
 Rename selected entry
+.It Ic R
+Rename directory entries
 .It Ic s
 Toggle sort by file size
 .It Ic S, ^J
diff --git a/nnn.c b/nnn.c
index 1161de74c7b3bd938f31ebc366c6e63db50c6bab..32a7d279199e9e774db801198cc140c25452d973 100644 (file)
--- a/nnn.c
+++ b/nnn.c
@@ -281,7 +281,8 @@ static char * const utils[] = {
        "xdg-open",
 #endif
        "nlay",
-       "atool"
+       "atool",
+       "vidir"
 };
 
 /* Common strings */
@@ -641,7 +642,7 @@ appendfilepath(const char *path, const size_t len)
                copybuflen += PATH_MAX;
                pcopybuf = xrealloc(pcopybuf, copybuflen);
                if (!pcopybuf) {
-                       printmsg("no memory!\n");
+                       printmsg("no memory!");
                        return FALSE;
                }
        }
@@ -1867,6 +1868,7 @@ show_help(char *path)
             "eM | Full media info\n"
             "en | Create new\n"
            "d^R | Rename entry\n"
+            "eR | Rename dir entries\n"
             "es | Toggle sort by size\n"
         "aS, ^J | Toggle du mode\n"
             "et | Toggle sort by mtime\n"
@@ -3070,6 +3072,35 @@ nochange:
                        close(fd);
                        xstrlcpy(oldname, tmp, NAME_MAX + 1);
                        goto begin;
+               case SEL_RENAMEALL:
+                       if (!get_output(g_buf, MAX_CMD_LEN, "which", utils[5], NULL, 0)) {
+                               printmsg("vidir missing");
+                               goto nochange;
+                       }
+
+                       /* Save the program start dir */
+                       tmp = getcwd(newpath, PATH_MAX);
+                       if (tmp == NULL) {
+                               printwarn();
+                               goto nochange;
+                       }
+
+                       /* Switch to current path for readline(3) */
+                       if (chdir(path) == -1) {
+                               printwarn();
+                               goto nochange;
+                       }
+
+                       spawn(utils[5], ".", NULL, NULL, F_NORMAL);
+
+                       /* Change back to program start dir */
+                       if (chdir(newpath) == -1)
+                               printwarn();
+
+                       /* Save current */
+                       if (ndents > 0)
+                               copycurname();
+                       goto begin;
                case SEL_HELP:
                        show_help(path);
                        break;
diff --git a/nnn.h b/nnn.h
index bb757f975ff509cefd96a8b9124c9d5c7b2d4b0b..8ab86575b781a348e529838dbe1a9d8428aa0928 100644 (file)
--- a/nnn.h
+++ b/nnn.h
@@ -39,6 +39,7 @@ enum action {
        SEL_OPEN,
        SEL_NEW,
        SEL_RENAME,
+       SEL_RENAMEALL,
        SEL_HELP,
        SEL_RUN,
        SEL_RUNARG,
@@ -158,6 +159,8 @@ static struct key bindings[] = {
        /* Show rename prompt */
        { CONTROL('R'),   SEL_RENAME,    "",     "" },
        { KEY_F(2),       SEL_RENAME,    "",     "" }, /* Undocumented */
+       /* Rename contents of current dir */
+       { 'R',            SEL_RENAMEALL, "",     "" },
        /* Show help */
        { '?',            SEL_HELP,      "",     "" },
        /* Run command */