]> Sergey Matveev's repositories - nnn.git/commitdiff
nmv: prefer selection if -u is active
authorNRK <nrk@disroot.org>
Fri, 17 Feb 2023 05:56:28 +0000 (11:56 +0600)
committerNRK <nrk@disroot.org>
Fri, 17 Feb 2023 13:22:46 +0000 (19:22 +0600)
the rename plugin always asks for "selection vs current" even when -u
flag is active. pass it to the plugin via `NNN_PREFER_SELECTION` so that
there's less distracting prompts.

plugins/.nmv
src/nnn.c

index 37e887de8cd291025a97a56d8818e29f40310587..63b56fa938bc6bf7f9b9e858c8a7ebd9a55df851 100755 (executable)
@@ -20,6 +20,7 @@
 EDITOR="${EDITOR:-vi}"
 TMPDIR="${TMPDIR:-/tmp}"
 NNN_INCLUDE_HIDDEN="${NNN_INCLUDE_HIDDEN:-0}"
+NNN_PREFER_SELECTION="${NNN_PREFER_SELECTION:-0}"
 VERBOSE="${VERBOSE:-0}"
 RECURSIVE="${RECURSIVE:-0}"
 
@@ -38,12 +39,16 @@ exit_status=0
 dst_file=$(mktemp "$TMPDIR/.nnnXXXXXX")
 
 if [ -s "$selection" ]; then
-       printf "Rename 'c'urrent / 's'election? "
-       read -r resp
+       if [ "$NNN_PREFER_SELECTION" -eq 1 ]; then
+               resp="s"
+       else
+               printf "Rename 'c'urrent / 's'election? "
+               read -r resp
 
-    if ! [ "$resp" = "c" ] && ! [ "$resp" = "s" ]; then
-        exit 1
-    fi
+               if ! [ "$resp" = "c" ] && ! [ "$resp" = "s" ]; then
+                       exit 1
+               fi
+       fi
 fi
 
 if [ "$resp" = "s" ]; then
index b351e202fe5884fe0625d5710120e8b0fbba856b..f35fb3f93599623a98f2e7f3bc5789f01fd05bf1 100644 (file)
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -7368,6 +7368,7 @@ nochange:
                        case SEL_RENAMEMUL:
                                endselection(TRUE);
                                setenv("NNN_INCLUDE_HIDDEN", xitoa(cfg.showhidden), 1);
+                               setenv("NNN_PREFER_SELECTION", xitoa(cfg.prefersel), 1);
                                setenv("NNN_LIST", listpath ? listroot : "", 1);
 
                                if (!(getutil(utils[UTIL_BASH])