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.
```
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 /
-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:
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
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
.Op Ar PATH
.Sh DESCRIPTION
.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
.Nm
defaults to the current directory if
/* Global context */
static struct entry *dents;
-static int ndents, cur;
+static int ndents, cur, total_dents;
static int idle;
static char *opener;
static char *fallback_opener;
xdirname(const char *path)
{
static char buf[PATH_MAX];
- char *last_slash;
+ static char *last_slash;
xstrlcpy(buf, path, PATH_MAX);
return (int) (TOUPPER(*s1) - TOUPPER(*s2));
}
+/* Trim all white space from both ends */
static char *
strstrip(char *s)
{
static int
setfilter(regex_t *regex, char *filter)
{
- char errbuf[LINE_MAX];
- size_t len;
- int r;
+ static char errbuf[LINE_MAX];
+ static size_t len;
+ static int r;
r = regcomp(regex, filter, REG_NOSUB | REG_EXTENDED | REG_ICASE);
if (r != 0) {
if (filter(re, dp->d_name) == 0)
continue;
- if (((n >> 5) << 5) == n) {
- *dents = realloc(*dents, (n + 32) * sizeof(**dents));
+ if (n == total_dents) {
+ total_dents += 64;
+ *dents = realloc(*dents, total_dents * sizeof(**dents));
if (*dents == NULL)
printerr(1, "realloc");
}
/* Get mode flags */
mkpath(path, dp->d_name, newpath, sizeof(newpath));
r = lstat(newpath, &sb);
- if (r == -1)
+ if (r == -1) {
+ if (*dents)
+ free(*dents);
printerr(1, "lstat");
+ }
(*dents)[n].mode = sb.st_mode;
(*dents)[n].t = sb.st_mtime;
(*dents)[n].size = sb.st_size;
/* Should never be null */
r = closedir(dirp);
- if (r == -1)
+ if (r == -1) {
+ if (*dents)
+ free(*dents);
printerr(1, "closedir");
+ }
return n;
}
if (r != 0)
return -1;
- dentfree(dents);
-
- ndents = 0;
- dents = NULL;
-
ndents = dentfill(path, &dents, visible, &re);
qsort(dents, ndents, sizeof(*dents), entrycmp);
{
static char cmd[MAX_CMD_LEN];
static char *runvi = "vi";
- static int status;
/* If default mime opener is set, use it */
if (opener) {
snprintf(cmd, MAX_CMD_LEN,
"%s \"%s\" > /dev/null 2>&1",
opener, newpath);
- status = system(cmd);
+ r = system(cmd);
continue;
}
/dev/null 2>&1",
fallback_opener,
newpath);
- status = system(cmd);
+ r = system(cmd);
continue;
} else {
- status++; /* Dummy operation */
printmsg("No association");
goto nochange;
}
mkpath(path, dents[cur].name, oldpath, sizeof(oldpath));
r = lstat(oldpath, &sb);
- if (r == -1)
+ if (r == -1) {
+ if (dents)
+ dentfree(dents);
printerr(1, "lstat");
- else
+ } else
show_stats(oldpath, dents[cur].name, &sb);
goto begin;