Show total size of non-filtered selected files in a directory.

This commit is contained in:
Arun Prakash Jana 2023-01-29 23:24:24 +05:30
parent 4f95796ede
commit 33827109d5
No known key found for this signature in database
GPG Key ID: A75979F35C080412
3 changed files with 26 additions and 1 deletions

5
nnn.1
View File

@ -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

View File

@ -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:

View File

@ -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 },