From bfb814bca6c3bb63a9b6df65236a7a3340792386 Mon Sep 17 00:00:00 2001 From: Arun Prakash Jana Date: Tue, 27 Mar 2018 08:05:47 +0530 Subject: [PATCH] Support ^A, ^E, ^U and ignore ^ chars at rename prompt --- README.md | 5 +++++ nnn.c | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/README.md b/README.md index d2e57f48..a04d2098 100644 --- 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 - ^A, ^E, ^U. ^L 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 0e630818..9d668ed9 100644 --- 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;