- [Keyboard shortcuts](#keyboard-shortcuts)
- [Leader key](#leader-key)
- [Contexts](#contexts)
+ - [Directory color](#directory-color)
- [Filters](#filters)
- [Navigate-as-you-type mode](#navigate-as-you-type-mode)
- [File indicators](#file-indicators)
#### Cmdline options
```
-usage: nnn [-b key] [-c N] [-e] [-i] [-l]
+usage: nnn [-b key] [-C] [-e] [-i] [-l]
[-p file] [-S] [-v] [-h] [PATH]
The missing terminal file manager for X.
optional args:
-b key bookmark key to open
- -c N dir color, disables if N>7
+ -C disable directory color
-e use exiftool instead of mediainfo
-i start in navigate-as-you-type mode
-l start in light mode
When a context is quit, the next active context is selected. If the last active context is quit, the program quits.
+#### Directory color
+
+Each context can have its own color for directories specified:
+
+ export NNN_CONTEXT_COLORS="1234"
+colors: 0-black, 1-red, 2-green, 3-yellow, 4-blue (default), 5-magenta, 6-cyan, 7-white
+
#### Filters
Filters support regexes to instantly (search-as-you-type) list the matching entries in the current directory.
#define SYMLINK_TO_DIR 0x1
#define MAX_HOME_LEN 64
#define MAX_CTX 4
-#define DOT_FILTER_LEN 8
+#define DOT_FILTER_LEN 7
/* Macros to define process spawn behaviour as flags */
#define F_NONE 0x00 /* no flag set */
uint showcolor : 1; /* Set to show dirs in blue */
uint dircolor : 1; /* Current status of dir color */
uint metaviewer : 1; /* Index of metadata viewer in utils[] */
- uint color : 3; /* Color code for directories */
uint ctxactive : 1; /* Context active or not */
- uint reserved : 10;
+ uint reserved : 13;
/* The following settings are global */
uint curctx : 2; /* Current context number */
uint picker : 1; /* Write selection to user-specified file */
char c_name[NAME_MAX + 1]; /* Current file name */
settings c_cfg; /* Current configuration */
char c_fltr[DOT_FILTER_LEN]; /* Hidden filter */
+ char color; /* Color code for directories */
} context;
/* GLOBALS */
/* Configuration, contexts */
-static settings cfg = {0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 4, 1, 0, 0, 0, 0, 0, 0};
+static settings cfg = {0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0};
static context g_ctx[MAX_CTX] __attribute__ ((aligned));
static struct entry *dents;
curs_set(FALSE); /* Hide cursor */
start_color();
use_default_colors();
- if (cfg.showcolor)
- init_pair(1, cfg.color, -1);
+ if (cfg.showcolor) {
+ init_pair(1, g_ctx[0].color, -1);
+ init_pair(2, g_ctx[1].color, -1);
+ init_pair(3, g_ctx[2].color, -1);
+ init_pair(4, g_ctx[3].color, -1);
+ }
settimeout(); /* One second */
}
static void resetdircolor(mode_t mode)
{
if (cfg.dircolor && !S_ISDIR(mode)) {
- attroff(COLOR_PAIR(1) | A_BOLD);
+ attroff(COLOR_PAIR(cfg.curctx + 1) | A_BOLD);
cfg.dircolor = 0;
}
}
if (cfg.useeditor)
dprintf(fd, "NNN_USE_EDITOR: 1\n");
+ if (getenv("NNN_CONTEXT_COLORS"))
+ dprintf(fd, "NNN_CONTEXT_COLORS: %s\n", getenv("NNN_CONTEXT_COLORS"));
if (idletimeout)
dprintf(fd, "NNN_IDLE_TIMEOUT: %d secs\n", idletimeout);
if (copier)
ncols -= 5;
if (cfg.showcolor) {
- attron(COLOR_PAIR(1) | A_BOLD);
+ attron(COLOR_PAIR(cfg.curctx + 1) | A_BOLD);
cfg.dircolor = 1;
}
/* Must reset e.g. no files in dir */
if (cfg.dircolor) {
- attroff(COLOR_PAIR(1) | A_BOLD);
+ attroff(COLOR_PAIR(cfg.curctx + 1) | A_BOLD);
cfg.dircolor = 0;
}
static void usage(void)
{
fprintf(stdout,
- "usage: nnn [-b key] [-c N] [-e] [-i] [-l]\n"
+ "usage: nnn [-b key] [-C] [-e] [-i] [-l]\n"
" [-p file] [-S] [-v] [-h] [PATH]\n\n"
"The missing terminal file manager for X.\n\n"
"positional args:\n"
" PATH start dir [default: current dir]\n\n"
"optional args:\n"
" -b key bookmark key to open\n"
- " -c N dir color, disables if N>7\n"
+ " -C disable directory color\n"
" -e use exiftool instead of mediainfo\n"
" -i start in navigate-as-you-type mode\n"
" -l start in light mode\n"
exit(1);
}
- while ((opt = getopt(argc, argv, "Slib:c:ep:vh")) != -1) {
+ while ((opt = getopt(argc, argv, "Slib:Cep:vh")) != -1) {
switch (opt) {
case 'S':
cfg.blkorder = 1;
case 'b':
ipath = optarg;
break;
- case 'c':
- if (atoi(optarg) > 7)
- cfg.showcolor = 0;
- else
- cfg.color = (uchar)atoi(optarg);
+ case 'C':
+ cfg.showcolor = 0;
break;
case 'e':
cfg.metaviewer = EXIFTOOL;
}
}
+ /* Get the context colors; copier used as tmp var */
+ if (cfg.showcolor) {
+ copier = getenv("NNN_CONTEXT_COLORS");
+ if (copier) {
+ opt = 0;
+ while (*copier && opt < MAX_CTX) {
+ if (*copier < '0' || *copier > '7') {
+ fprintf(stderr, "invalid color code\n");
+ exit(1);
+ } else
+ g_ctx[opt].color = *copier - '0';
+
+ ++copier;
+ ++opt;
+ }
+
+ while (opt != MAX_CTX) {
+ g_ctx[opt].color = 4;
+ ++opt;
+ }
+ } else
+ for (opt = 0; opt < MAX_CTX; ++opt)
+ g_ctx[opt].color = 4; /* Default color is blue */
+ }
+
/* Parse bookmarks string */
if (parsebmstr() < 0) {
fprintf(stderr, "ERROR parsing NNN_BMS: set single-char bookmark keys only\n");