]> Sergey Matveev's repositories - nnn.git/commitdiff
Show total size of non-filtered selected files in a directory.
authorArun Prakash Jana <engineerarun@gmail.com>
Sun, 29 Jan 2023 17:54:24 +0000 (23:24 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Sun, 29 Jan 2023 18:44:54 +0000 (00:14 +0530)
nnn.1
src/nnn.c
src/nnn.h

diff --git a/nnn.1 b/nnn.1
index 9d6d813daf4702e69ac1e726676cea36286ffec7..cc86bf7cb02f0e885a025bc52627c1a52231e585 100644 (file)
--- 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
index 57d76b2f7775f09c8c029acd3c71d9c7e634b837..b821f80886af0fc8d8d7ea495b266038b91da36a 100644 (file)
--- 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:
index cb4d6d692686ccec1d2887b569cc69f4b594399a..3e4ea19ca3bfb2f57c795eded3babbb21e4cf497 100644 (file)
--- 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 },