commit 33827109d5281a87a14a4a044c0db215e6e814df
parent 4f95796edecc77efe17d32cb8f015e6c86d169a2
Author: Arun Prakash Jana <engineerarun@gmail.com>
Date: Sun, 29 Jan 2023 23:24:24 +0530
Show total size of non-filtered selected files in a directory.
Diffstat:
3 files changed, 26 insertions(+), 1 deletion(-)
diff --git a/nnn.1 b/nnn.1
@@ -317,6 +317,11 @@ To edit the selection use the _edit selection_ key. Editing doesn't end the
selection mode. You can add more files to the selection and edit the list
again. If no file is selected in the current session, this option attempts
to list the selection file.
+.Pp
+.Nm
+can show the total size of non-filtered selected files listed in a
+directory. For directories, only the size of the directory is added by
+default. To add the size of the contents of a directory, switch to du mode.
.Sh FIND AND LIST
There are two ways to search and list:
.Pp
diff --git a/src/nnn.c b/src/nnn.c
@@ -5076,7 +5076,8 @@ static void show_help(const char *path)
"ca Select all%-14cA Invert sel\n"
"9p ^P Copy here%-12cw ^W Cp/mv sel as\n"
"9v ^V Move here%-15cE Edit sel list\n"
- "9x ^X Delete%-16cEsc Send to FIFO\n"
+ "9x ^X Delete%-18cS Listed sel size\n"
+ "aEsc Send to FIFO\n"
"0\n"
"1MISC\n"
"8Alt ; Select plugin%-11c= Launch app\n"
@@ -6633,6 +6634,19 @@ static bool cdprep(char *lastdir, char *lastname, char *path, char *newpath)
return cfg.filtermode;
}
+static void showselsize(const char *path)
+{
+ off_t sz = 0;
+ int len = scanselforpath(path, FALSE);
+
+ for (int r = 0; r < ndents; ++r)
+ if (findinsel(findselpos,
+ len + xstrsncpy(g_sel + len, pdents[r].name, pdents[r].nlen)))
+ sz += cfg.blkorder ? pdents[r].blocks : pdents[r].size;
+
+ printmsg(coolsize(cfg.blkorder ? sz << blk_shift : sz));
+}
+
static bool browse(char *ipath, const char *session, int pkey)
{
alignas(max_align_t) char newpath[PATH_MAX];
@@ -7843,6 +7857,9 @@ nochange:
if (g_state.runplugin == 1) /* Allow filtering in plugins directory */
presel = FILTER;
goto begin;
+ case SEL_SELSIZE:
+ showselsize(path);
+ goto nochange;
case SEL_SHELL: // fallthrough
case SEL_LAUNCH: // fallthrough
case SEL_PROMPT:
diff --git a/src/nnn.h b/src/nnn.h
@@ -105,6 +105,7 @@ enum action {
SEL_AUTONEXT,
SEL_EDIT,
SEL_PLUGIN,
+ SEL_SELSIZE,
SEL_SHELL,
SEL_LAUNCH,
SEL_PROMPT,
@@ -257,6 +258,8 @@ static struct key bindings[] = {
{ 'e', SEL_EDIT },
/* Run a plugin */
{ ';', SEL_PLUGIN },
+ /* Show total size of listed selection */
+ { 'S', SEL_SELSIZE },
/* Run command */
{ '!', SEL_SHELL },
{ CONTROL(']'), SEL_SHELL },