mirror of
https://github.com/jarun/nnn.git
synced 2024-11-28 05:41:31 +00:00
Show apparent size
This commit is contained in:
parent
cca1d60b98
commit
b7a6b1c12a
|
@ -235,7 +235,8 @@ optional args:
|
||||||
^R | Rename entry
|
^R | Rename entry
|
||||||
r | Open dir in vidir
|
r | Open dir in vidir
|
||||||
s | Toggle sort by size
|
s | Toggle sort by size
|
||||||
S, ^J | Toggle du mode
|
S | Toggle apparent size
|
||||||
|
^J | Toggle du mode
|
||||||
t | Toggle sort by mtime
|
t | Toggle sort by mtime
|
||||||
!, ^] | Spawn SHELL in dir
|
!, ^] | Spawn SHELL in dir
|
||||||
R | Run custom script
|
R | Run custom script
|
||||||
|
|
4
nnn.1
4
nnn.1
|
@ -85,7 +85,9 @@ Rename selected entry
|
||||||
Open directory in vidir
|
Open directory in vidir
|
||||||
.It Ic s
|
.It Ic s
|
||||||
Toggle sort by file size
|
Toggle sort by file size
|
||||||
.It Ic S, ^J
|
.It Ic S
|
||||||
|
Toggle sort by apparent size
|
||||||
|
.It Ic ^J
|
||||||
Toggle disk usage analyzer mode
|
Toggle disk usage analyzer mode
|
||||||
.It Ic t
|
.It Ic t
|
||||||
Toggle sort by time modified
|
Toggle sort by time modified
|
||||||
|
|
57
nnn.c
57
nnn.c
|
@ -241,6 +241,7 @@ typedef struct {
|
||||||
ushort filtermode : 1; /* Set to enter filter mode */
|
ushort filtermode : 1; /* Set to enter filter mode */
|
||||||
ushort mtimeorder : 1; /* Set to sort by time modified */
|
ushort mtimeorder : 1; /* Set to sort by time modified */
|
||||||
ushort sizeorder : 1; /* Set to sort by file size */
|
ushort sizeorder : 1; /* Set to sort by file size */
|
||||||
|
ushort apparentsz : 1; /* Set to sort by apparent size (disk usage) */
|
||||||
ushort blkorder : 1; /* Set to sort by blocks used (disk usage) */
|
ushort blkorder : 1; /* Set to sort by blocks used (disk usage) */
|
||||||
ushort showhidden : 1; /* Set to show hidden files */
|
ushort showhidden : 1; /* Set to show hidden files */
|
||||||
ushort copymode : 1; /* Set when copying files */
|
ushort copymode : 1; /* Set when copying files */
|
||||||
|
@ -256,7 +257,7 @@ typedef struct {
|
||||||
/* GLOBALS */
|
/* GLOBALS */
|
||||||
|
|
||||||
/* Configuration */
|
/* Configuration */
|
||||||
static settings cfg = {0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 4};
|
static settings cfg = {0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 4};
|
||||||
|
|
||||||
static struct entry *dents;
|
static struct entry *dents;
|
||||||
static char *pnamebuf, *pcopybuf;
|
static char *pnamebuf, *pcopybuf;
|
||||||
|
@ -272,6 +273,7 @@ static blkcnt_t dir_blocks;
|
||||||
static ulong num_files;
|
static ulong num_files;
|
||||||
static uint open_max;
|
static uint open_max;
|
||||||
static bm bookmark[BM_MAX];
|
static bm bookmark[BM_MAX];
|
||||||
|
static uchar BLK_SHIFT = 9;
|
||||||
|
|
||||||
static uchar crc8table[CRC8_TABLE_LEN];
|
static uchar crc8table[CRC8_TABLE_LEN];
|
||||||
static uchar g_crc;
|
static uchar g_crc;
|
||||||
|
@ -1558,7 +1560,7 @@ printent_long(struct entry *ent, int sel, uint namecols)
|
||||||
|
|
||||||
if (S_ISDIR(ent->mode)) {
|
if (S_ISDIR(ent->mode)) {
|
||||||
if (cfg.blkorder)
|
if (cfg.blkorder)
|
||||||
printw("%s%-16.16s %8.8s/ %s/\n", CURSYM(sel), buf, coolsize(ent->blocks << 9), pname);
|
printw("%s%-16.16s %8.8s/ %s/\n", CURSYM(sel), buf, coolsize(ent->blocks << BLK_SHIFT), pname);
|
||||||
else
|
else
|
||||||
printw("%s%-16.16s / %s/\n", CURSYM(sel), buf, pname);
|
printw("%s%-16.16s / %s/\n", CURSYM(sel), buf, pname);
|
||||||
} else if (S_ISLNK(ent->mode)) {
|
} else if (S_ISLNK(ent->mode)) {
|
||||||
|
@ -1576,12 +1578,12 @@ printent_long(struct entry *ent, int sel, uint namecols)
|
||||||
printw("%s%-16.16s c %s\n", CURSYM(sel), buf, pname);
|
printw("%s%-16.16s c %s\n", CURSYM(sel), buf, pname);
|
||||||
else if (ent->mode & 0100) {
|
else if (ent->mode & 0100) {
|
||||||
if (cfg.blkorder)
|
if (cfg.blkorder)
|
||||||
printw("%s%-16.16s %8.8s* %s*\n", CURSYM(sel), buf, coolsize(ent->blocks << 9), pname);
|
printw("%s%-16.16s %8.8s* %s*\n", CURSYM(sel), buf, coolsize(ent->blocks << BLK_SHIFT), pname);
|
||||||
else
|
else
|
||||||
printw("%s%-16.16s %8.8s* %s*\n", CURSYM(sel), buf, coolsize(ent->size), pname);
|
printw("%s%-16.16s %8.8s* %s*\n", CURSYM(sel), buf, coolsize(ent->size), pname);
|
||||||
} else {
|
} else {
|
||||||
if (cfg.blkorder)
|
if (cfg.blkorder)
|
||||||
printw("%s%-16.16s %8.8s %s\n", CURSYM(sel), buf, coolsize(ent->blocks << 9), pname);
|
printw("%s%-16.16s %8.8s %s\n", CURSYM(sel), buf, coolsize(ent->blocks << BLK_SHIFT), pname);
|
||||||
else
|
else
|
||||||
printw("%s%-16.16s %8.8s %s\n", CURSYM(sel), buf, coolsize(ent->size), pname);
|
printw("%s%-16.16s %8.8s %s\n", CURSYM(sel), buf, coolsize(ent->size), pname);
|
||||||
}
|
}
|
||||||
|
@ -1951,7 +1953,8 @@ show_help(char *path)
|
||||||
"d^R | Rename entry\n"
|
"d^R | Rename entry\n"
|
||||||
"er | Open dir in vidir\n"
|
"er | Open dir in vidir\n"
|
||||||
"es | Toggle sort by size\n"
|
"es | Toggle sort by size\n"
|
||||||
"aS, ^J | Toggle du mode\n"
|
"eS | Toggle apparent size\n"
|
||||||
|
"d^J | Toggle du mode\n"
|
||||||
"et | Toggle sort by mtime\n"
|
"et | Toggle sort by mtime\n"
|
||||||
"a!, ^] | Spawn SHELL in dir\n"
|
"a!, ^] | Spawn SHELL in dir\n"
|
||||||
"eR | Run custom script\n"
|
"eR | Run custom script\n"
|
||||||
|
@ -2042,6 +2045,8 @@ show_help(char *path)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int (*nftw_fn) (const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf);
|
||||||
|
|
||||||
static int
|
static int
|
||||||
sum_bsizes(const char *fpath, const struct stat *sb,
|
sum_bsizes(const char *fpath, const struct stat *sb,
|
||||||
int typeflag, struct FTW *ftwbuf)
|
int typeflag, struct FTW *ftwbuf)
|
||||||
|
@ -2053,6 +2058,17 @@ sum_bsizes(const char *fpath, const struct stat *sb,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
sum_sizes(const char *fpath, const struct stat *sb,
|
||||||
|
int typeflag, struct FTW *ftwbuf)
|
||||||
|
{
|
||||||
|
if (sb->st_size && (typeflag == FTW_F || typeflag == FTW_D))
|
||||||
|
ent_blocks += sb->st_size;
|
||||||
|
|
||||||
|
++num_files;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
dentfill(char *path, struct entry **dents,
|
dentfill(char *path, struct entry **dents,
|
||||||
int (*filter)(regex_t *, char *), regex_t *re)
|
int (*filter)(regex_t *, char *), regex_t *re)
|
||||||
|
@ -2105,16 +2121,14 @@ dentfill(char *path, struct entry **dents,
|
||||||
ent_blocks = 0;
|
ent_blocks = 0;
|
||||||
mkpath(path, namep, g_buf, PATH_MAX);
|
mkpath(path, namep, g_buf, PATH_MAX);
|
||||||
|
|
||||||
if (nftw(g_buf, sum_bsizes, open_max, FTW_MOUNT | FTW_PHYS) == -1) {
|
if (nftw(g_buf, nftw_fn, open_max, FTW_MOUNT | FTW_PHYS) == -1) {
|
||||||
printmsg(messages[STR_NFTWFAIL_ID]);
|
printmsg(messages[STR_NFTWFAIL_ID]);
|
||||||
dir_blocks += sb.st_blocks;
|
dir_blocks += (cfg.apparentsz ? sb.st_size : sb.st_blocks);
|
||||||
} else
|
} else
|
||||||
dir_blocks += ent_blocks;
|
dir_blocks += ent_blocks;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (sb.st_blocks)
|
dir_blocks += (cfg.apparentsz ? sb.st_size : sb.st_blocks);
|
||||||
dir_blocks += sb.st_blocks;
|
|
||||||
|
|
||||||
++num_files;
|
++num_files;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2183,9 +2197,9 @@ dentfill(char *path, struct entry **dents,
|
||||||
num_saved = num_files + 1;
|
num_saved = num_files + 1;
|
||||||
mkpath(path, namep, g_buf, PATH_MAX);
|
mkpath(path, namep, g_buf, PATH_MAX);
|
||||||
|
|
||||||
if (nftw(g_buf, sum_bsizes, open_max, FTW_MOUNT | FTW_PHYS) == -1) {
|
if (nftw(g_buf, nftw_fn, open_max, FTW_MOUNT | FTW_PHYS) == -1) {
|
||||||
printmsg(messages[STR_NFTWFAIL_ID]);
|
printmsg(messages[STR_NFTWFAIL_ID]);
|
||||||
dentp->blocks = sb.st_blocks;
|
dentp->blocks = (cfg.apparentsz ? sb.st_size : sb.st_blocks);
|
||||||
} else
|
} else
|
||||||
dentp->blocks = ent_blocks;
|
dentp->blocks = ent_blocks;
|
||||||
|
|
||||||
|
@ -2194,7 +2208,7 @@ dentfill(char *path, struct entry **dents,
|
||||||
else
|
else
|
||||||
num_files = num_saved;
|
num_files = num_saved;
|
||||||
} else {
|
} else {
|
||||||
dentp->blocks = sb.st_blocks;
|
dentp->blocks = (cfg.apparentsz ? sb.st_size : sb.st_blocks);
|
||||||
dir_blocks += dentp->blocks;
|
dir_blocks += dentp->blocks;
|
||||||
++num_files;
|
++num_files;
|
||||||
}
|
}
|
||||||
|
@ -2920,14 +2934,30 @@ nochange:
|
||||||
case SEL_FSIZE:
|
case SEL_FSIZE:
|
||||||
cfg.sizeorder ^= 1;
|
cfg.sizeorder ^= 1;
|
||||||
cfg.mtimeorder = 0;
|
cfg.mtimeorder = 0;
|
||||||
|
cfg.apparentsz = 0;
|
||||||
cfg.blkorder = 0;
|
cfg.blkorder = 0;
|
||||||
cfg.copymode = 0;
|
cfg.copymode = 0;
|
||||||
/* Save current */
|
/* Save current */
|
||||||
if (ndents)
|
if (ndents)
|
||||||
copycurname();
|
copycurname();
|
||||||
goto begin;
|
goto begin;
|
||||||
|
case SEL_ASIZE:
|
||||||
|
cfg.apparentsz ^= 1;
|
||||||
|
if (cfg.apparentsz) {
|
||||||
|
nftw_fn = &sum_sizes;
|
||||||
|
cfg.blkorder = 1;
|
||||||
|
BLK_SHIFT = 0;
|
||||||
|
} else
|
||||||
|
cfg.blkorder = 0; // fallthrough
|
||||||
case SEL_BSIZE:
|
case SEL_BSIZE:
|
||||||
|
if (sel == SEL_BSIZE) {
|
||||||
|
if (!cfg.apparentsz)
|
||||||
cfg.blkorder ^= 1;
|
cfg.blkorder ^= 1;
|
||||||
|
nftw_fn = &sum_bsizes;
|
||||||
|
cfg.apparentsz = 0;
|
||||||
|
BLK_SHIFT = 9;
|
||||||
|
}
|
||||||
|
|
||||||
if (cfg.blkorder) {
|
if (cfg.blkorder) {
|
||||||
cfg.showdetail = 1;
|
cfg.showdetail = 1;
|
||||||
printptr = &printent_long;
|
printptr = &printent_long;
|
||||||
|
@ -2942,6 +2972,7 @@ nochange:
|
||||||
case SEL_MTIME:
|
case SEL_MTIME:
|
||||||
cfg.mtimeorder ^= 1;
|
cfg.mtimeorder ^= 1;
|
||||||
cfg.sizeorder = 0;
|
cfg.sizeorder = 0;
|
||||||
|
cfg.apparentsz = 0;
|
||||||
cfg.blkorder = 0;
|
cfg.blkorder = 0;
|
||||||
cfg.copymode = 0;
|
cfg.copymode = 0;
|
||||||
/* Save current */
|
/* Save current */
|
||||||
|
|
8
nnn.h
8
nnn.h
|
@ -57,8 +57,9 @@ enum action {
|
||||||
SEL_ARCHIVE,
|
SEL_ARCHIVE,
|
||||||
SEL_LIST,
|
SEL_LIST,
|
||||||
SEL_EXTRACT,
|
SEL_EXTRACT,
|
||||||
SEL_FSIZE,
|
SEL_FSIZE, /* file size */
|
||||||
SEL_BSIZE,
|
SEL_ASIZE, /* apparent size */
|
||||||
|
SEL_BSIZE, /* block size */
|
||||||
SEL_MTIME,
|
SEL_MTIME,
|
||||||
SEL_REDRAW,
|
SEL_REDRAW,
|
||||||
SEL_COPY,
|
SEL_COPY,
|
||||||
|
@ -171,8 +172,9 @@ static struct key bindings[] = {
|
||||||
{ CONTROL('F'), SEL_EXTRACT, "-x", "" },
|
{ CONTROL('F'), SEL_EXTRACT, "-x", "" },
|
||||||
/* Toggle sort by size */
|
/* Toggle sort by size */
|
||||||
{ 's', SEL_FSIZE, "", "" },
|
{ 's', SEL_FSIZE, "", "" },
|
||||||
|
/* Sort by apparent size including dir contents */
|
||||||
|
{ 'S', SEL_ASIZE, "", "" },
|
||||||
/* Sort by total block count including dir contents */
|
/* Sort by total block count including dir contents */
|
||||||
{ 'S', SEL_BSIZE, "", "" },
|
|
||||||
{ CONTROL('J'), SEL_BSIZE, "", "" },
|
{ CONTROL('J'), SEL_BSIZE, "", "" },
|
||||||
/* Toggle sort by time */
|
/* Toggle sort by time */
|
||||||
{ 't', SEL_MTIME, "", "" },
|
{ 't', SEL_MTIME, "", "" },
|
||||||
|
|
Loading…
Reference in a new issue