]> Sergey Matveev's repositories - nnn.git/commitdiff
Support ^A, ^E, ^U and ignore ^ chars at rename prompt
authorArun Prakash Jana <engineerarun@gmail.com>
Tue, 27 Mar 2018 02:35:47 +0000 (08:05 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Wed, 28 Mar 2018 02:38:02 +0000 (08:08 +0530)
README.md
nnn.c

index d2e57f484dc1a7ad63526927e1f14af2a431346d..a04d2098ebdc5426d7d082ee49a6d1fb17bbbb9f 100644 (file)
--- a/README.md
+++ b/README.md
@@ -63,6 +63,7 @@ Have fun with it! PRs are welcome. Check out [#1](https://github.com/jarun/nnn/i
   - [change dir color](#change-dir-color)
   - [file copy, move, delete](#file-copy-move-delete)
   - [boost chdir prompt](#boost-chdir-prompt)
+  - [work faster at rename prompt](#work-faster-at-rename-prompt)
   - [set idle timeout](#set-idle-timeout)
   - [show hot plugged drives](#show-hot-plugged-drives)
 - [Why fork?](#why-fork)
@@ -440,6 +441,10 @@ In addition, nnn integrates with vidir. vidir supports batch file move and delet
 
 `nnn` uses libreadline for the chdir prompt input. So all the fantastic features of readline (e.g. case insensitive tab completion, history, reverse-i-search) are available to you based on your readline [configuration](https://cnswww.cns.cwru.edu/php/chet/readline/readline.html#SEC9).
 
+#### work faster at rename prompt
+
+The rename prompt supports some bash-like command-line shortcuts - <kbd>^A</kbd>, <kbd>^E</kbd>, <kbd>^U</kbd>. <kbd>^L</kbd> clears the name.
+
 #### set idle timeout
 
 The terminal screensaver is disabled by default. To set the wait time in seconds, use environment variable `NNN_IDLE_TIMEOUT`.
diff --git a/nnn.c b/nnn.c
index 0e630818578ccc5cf47e91d18aa5d25c57e417ef..9d668ed90dedc61f0d5d1fdba684cbbb8865c350 100644 (file)
--- a/nnn.c
+++ b/nnn.c
@@ -1235,6 +1235,28 @@ xreadline(char *fname)
                                        continue;
                                }
 
+                               if (*ch == CONTROL('A')) {
+                                       pos = 0;
+                                       continue;
+                               }
+
+                               if (*ch == CONTROL('E')) {
+                                       pos = len;
+                                       continue;
+                               }
+
+                               if (*ch == CONTROL('U')) {
+                                       clearprompt();
+                                       memmove(buf, buf + pos, (len - pos) << 2);
+                                       len -= pos;
+                                       pos = 0;
+                                       continue;
+                               }
+
+                               /* Filter out all other control chars */
+                               if (keyname(*ch)[0] == '^')
+                                       continue;
+
                                /* TAB breaks cursor position, ignore it */
                                if (*ch == '\t')
                                        continue;