mirror of
https://github.com/jarun/nnn.git
synced 2024-11-28 05:41:31 +00:00
Hold allocated memory till program exit
This commit is contained in:
parent
f10ef49534
commit
34a8ec2881
|
@ -42,7 +42,7 @@ Noice is Not Noice, a noicer fork...
|
||||||
|
|
||||||
nnn is a fork of [noice](http://git.2f30.org/noice/), a blazing-fast lightweight terminal file browser with easy keyboard shortcuts for navigation, opening files and running tasks. noice is developed considering terminal based systems. There is no config file and mime associations are hard-coded. However, the incredible user-friendliness and speed make it a perfect utility on modern distros.
|
nnn is a fork of [noice](http://git.2f30.org/noice/), a blazing-fast lightweight terminal file browser with easy keyboard shortcuts for navigation, opening files and running tasks. noice is developed considering terminal based systems. There is no config file and mime associations are hard-coded. However, the incredible user-friendliness and speed make it a perfect utility on modern distros.
|
||||||
|
|
||||||
nnn can use the default desktop opener at runtime. It adds new navigation options, enhanced DE integration, a disk usage analyzer mode, comprehensive file details and much more. For a complete list, see [nnn toppings](#nnn-toppings).
|
nnn can use the default desktop opener at runtime. It adds new navigation options, enhanced DE integration, a disk usage analyzer mode, comprehensive file details and much more. For a complete list, see [nnn toppings](#nnn-toppings). Add to it a huge [performance](#performance) boost.
|
||||||
|
|
||||||
Follow the instructions in the [quickstart](#quickstart) section and see how nnn simplifies those long desktop sessions.
|
Follow the instructions in the [quickstart](#quickstart) section and see how nnn simplifies those long desktop sessions.
|
||||||
|
|
||||||
|
@ -128,7 +128,7 @@ nnn vs. ncdu memory usage while listing an external disk with 13,790 files in di
|
||||||
```
|
```
|
||||||
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
|
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
|
||||||
31163 vaio 20 0 65508 53980 2320 S 0.0 1.1 0:01.96 ncdu /
|
31163 vaio 20 0 65508 53980 2320 S 0.0 1.1 0:01.96 ncdu /
|
||||||
28863 vaio 20 0 24276 11088 2776 S 0.3 0.2 0:02.61 nnn -d
|
28863 vaio 20 0 21348 7812 2476 S 0.0 0.2 0:01.75 nnn -d
|
||||||
```
|
```
|
||||||
|
|
||||||
nnn vs. mc vs. ranger memory usage while viewing a directory with 10,178 files, sorted by size:
|
nnn vs. mc vs. ranger memory usage while viewing a directory with 10,178 files, sorted by size:
|
||||||
|
@ -137,7 +137,7 @@ nnn vs. mc vs. ranger memory usage while viewing a directory with 10,178 files,
|
||||||
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
|
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
|
||||||
22465 vaio 20 0 233956 192136 7896 S 0.0 3.9 0:05.31 /usr/bin/python -O /usr/bin/ranger
|
22465 vaio 20 0 233956 192136 7896 S 0.0 3.9 0:05.31 /usr/bin/python -O /usr/bin/ranger
|
||||||
20369 vaio 20 0 64664 10980 6888 S 0.0 0.2 0:00.70 mc
|
20369 vaio 20 0 64664 10980 6888 S 0.0 0.2 0:00.70 mc
|
||||||
28863 vaio 20 0 20600 7220 2648 S 0.0 0.1 0:00.36 nnn -d
|
28863 vaio 20 0 19876 6436 2620 S 0.0 0.1 0:00.19 nnn -d
|
||||||
```
|
```
|
||||||
|
|
||||||
### Installation
|
### Installation
|
||||||
|
|
2
nnn.1
2
nnn.1
|
@ -13,7 +13,7 @@
|
||||||
.Op Ar PATH
|
.Op Ar PATH
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
.Nm
|
.Nm
|
||||||
(Noice is Not Noice) is a fork of the noice terminal file browser with improved desktop integration, navigation, disk usage analyzer mode, comprehensive file details and much more. It remains a simple and efficient file browser that stays out of your way.
|
(Noice is Not Noice) is a performance-optimized fork of the noice terminal file browser with improved desktop integration, navigation, disk usage analyzer mode, comprehensive file details and much more. It remains a simple and efficient file browser that stays out of your way.
|
||||||
.Pp
|
.Pp
|
||||||
.Nm
|
.Nm
|
||||||
defaults to the current directory if
|
defaults to the current directory if
|
||||||
|
|
43
nnn.c
43
nnn.c
|
@ -129,7 +129,7 @@ extern void add_history(const char *string);
|
||||||
|
|
||||||
/* Global context */
|
/* Global context */
|
||||||
static struct entry *dents;
|
static struct entry *dents;
|
||||||
static int ndents, cur;
|
static int ndents, cur, total_dents;
|
||||||
static int idle;
|
static int idle;
|
||||||
static char *opener;
|
static char *opener;
|
||||||
static char *fallback_opener;
|
static char *fallback_opener;
|
||||||
|
@ -239,7 +239,7 @@ static char *
|
||||||
xdirname(const char *path)
|
xdirname(const char *path)
|
||||||
{
|
{
|
||||||
static char buf[PATH_MAX];
|
static char buf[PATH_MAX];
|
||||||
char *last_slash;
|
static char *last_slash;
|
||||||
|
|
||||||
xstrlcpy(buf, path, PATH_MAX);
|
xstrlcpy(buf, path, PATH_MAX);
|
||||||
|
|
||||||
|
@ -366,6 +366,7 @@ xstricmp(const char *s1, const char *s2)
|
||||||
return (int) (TOUPPER(*s1) - TOUPPER(*s2));
|
return (int) (TOUPPER(*s1) - TOUPPER(*s2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Trim all white space from both ends */
|
||||||
static char *
|
static char *
|
||||||
strstrip(char *s)
|
strstrip(char *s)
|
||||||
{
|
{
|
||||||
|
@ -411,9 +412,9 @@ openwith(char *file)
|
||||||
static int
|
static int
|
||||||
setfilter(regex_t *regex, char *filter)
|
setfilter(regex_t *regex, char *filter)
|
||||||
{
|
{
|
||||||
char errbuf[LINE_MAX];
|
static char errbuf[LINE_MAX];
|
||||||
size_t len;
|
static size_t len;
|
||||||
int r;
|
static int r;
|
||||||
|
|
||||||
r = regcomp(regex, filter, REG_NOSUB | REG_EXTENDED | REG_ICASE);
|
r = regcomp(regex, filter, REG_NOSUB | REG_EXTENDED | REG_ICASE);
|
||||||
if (r != 0) {
|
if (r != 0) {
|
||||||
|
@ -1034,8 +1035,9 @@ dentfill(char *path, struct entry **dents,
|
||||||
if (filter(re, dp->d_name) == 0)
|
if (filter(re, dp->d_name) == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (((n >> 5) << 5) == n) {
|
if (n == total_dents) {
|
||||||
*dents = realloc(*dents, (n + 32) * sizeof(**dents));
|
total_dents += 64;
|
||||||
|
*dents = realloc(*dents, total_dents * sizeof(**dents));
|
||||||
if (*dents == NULL)
|
if (*dents == NULL)
|
||||||
printerr(1, "realloc");
|
printerr(1, "realloc");
|
||||||
}
|
}
|
||||||
|
@ -1044,8 +1046,11 @@ dentfill(char *path, struct entry **dents,
|
||||||
/* Get mode flags */
|
/* Get mode flags */
|
||||||
mkpath(path, dp->d_name, newpath, sizeof(newpath));
|
mkpath(path, dp->d_name, newpath, sizeof(newpath));
|
||||||
r = lstat(newpath, &sb);
|
r = lstat(newpath, &sb);
|
||||||
if (r == -1)
|
if (r == -1) {
|
||||||
|
if (*dents)
|
||||||
|
free(*dents);
|
||||||
printerr(1, "lstat");
|
printerr(1, "lstat");
|
||||||
|
}
|
||||||
(*dents)[n].mode = sb.st_mode;
|
(*dents)[n].mode = sb.st_mode;
|
||||||
(*dents)[n].t = sb.st_mtime;
|
(*dents)[n].t = sb.st_mtime;
|
||||||
(*dents)[n].size = sb.st_size;
|
(*dents)[n].size = sb.st_size;
|
||||||
|
@ -1075,8 +1080,11 @@ dentfill(char *path, struct entry **dents,
|
||||||
|
|
||||||
/* Should never be null */
|
/* Should never be null */
|
||||||
r = closedir(dirp);
|
r = closedir(dirp);
|
||||||
if (r == -1)
|
if (r == -1) {
|
||||||
|
if (*dents)
|
||||||
|
free(*dents);
|
||||||
printerr(1, "closedir");
|
printerr(1, "closedir");
|
||||||
|
}
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1128,11 +1136,6 @@ populate(char *path, char *oldpath, char *fltr)
|
||||||
if (r != 0)
|
if (r != 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
dentfree(dents);
|
|
||||||
|
|
||||||
ndents = 0;
|
|
||||||
dents = NULL;
|
|
||||||
|
|
||||||
ndents = dentfill(path, &dents, visible, &re);
|
ndents = dentfill(path, &dents, visible, &re);
|
||||||
|
|
||||||
qsort(dents, ndents, sizeof(*dents), entrycmp);
|
qsort(dents, ndents, sizeof(*dents), entrycmp);
|
||||||
|
@ -1334,14 +1337,13 @@ nochange:
|
||||||
{
|
{
|
||||||
static char cmd[MAX_CMD_LEN];
|
static char cmd[MAX_CMD_LEN];
|
||||||
static char *runvi = "vi";
|
static char *runvi = "vi";
|
||||||
static int status;
|
|
||||||
|
|
||||||
/* If default mime opener is set, use it */
|
/* If default mime opener is set, use it */
|
||||||
if (opener) {
|
if (opener) {
|
||||||
snprintf(cmd, MAX_CMD_LEN,
|
snprintf(cmd, MAX_CMD_LEN,
|
||||||
"%s \"%s\" > /dev/null 2>&1",
|
"%s \"%s\" > /dev/null 2>&1",
|
||||||
opener, newpath);
|
opener, newpath);
|
||||||
status = system(cmd);
|
r = system(cmd);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1370,10 +1372,9 @@ nochange:
|
||||||
/dev/null 2>&1",
|
/dev/null 2>&1",
|
||||||
fallback_opener,
|
fallback_opener,
|
||||||
newpath);
|
newpath);
|
||||||
status = system(cmd);
|
r = system(cmd);
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
status++; /* Dummy operation */
|
|
||||||
printmsg("No association");
|
printmsg("No association");
|
||||||
goto nochange;
|
goto nochange;
|
||||||
}
|
}
|
||||||
|
@ -1572,9 +1573,11 @@ nochange:
|
||||||
mkpath(path, dents[cur].name, oldpath, sizeof(oldpath));
|
mkpath(path, dents[cur].name, oldpath, sizeof(oldpath));
|
||||||
|
|
||||||
r = lstat(oldpath, &sb);
|
r = lstat(oldpath, &sb);
|
||||||
if (r == -1)
|
if (r == -1) {
|
||||||
|
if (dents)
|
||||||
|
dentfree(dents);
|
||||||
printerr(1, "lstat");
|
printerr(1, "lstat");
|
||||||
else
|
} else
|
||||||
show_stats(oldpath, dents[cur].name, &sb);
|
show_stats(oldpath, dents[cur].name, &sb);
|
||||||
|
|
||||||
goto begin;
|
goto begin;
|
||||||
|
|
Loading…
Reference in a new issue