mirror of
https://github.com/jarun/nnn.git
synced 2024-11-28 05:41:31 +00:00
Per-context directory color
This commit is contained in:
parent
4c576cfded
commit
36b7b433f9
12
README.md
12
README.md
|
@ -50,6 +50,7 @@ It runs on Linux, macOS, Raspberry Pi, Cygwin, Linux subsystem for Windows and T
|
||||||
- [Keyboard shortcuts](#keyboard-shortcuts)
|
- [Keyboard shortcuts](#keyboard-shortcuts)
|
||||||
- [Leader key](#leader-key)
|
- [Leader key](#leader-key)
|
||||||
- [Contexts](#contexts)
|
- [Contexts](#contexts)
|
||||||
|
- [Directory color](#directory-color)
|
||||||
- [Filters](#filters)
|
- [Filters](#filters)
|
||||||
- [Navigate-as-you-type mode](#navigate-as-you-type-mode)
|
- [Navigate-as-you-type mode](#navigate-as-you-type-mode)
|
||||||
- [File indicators](#file-indicators)
|
- [File indicators](#file-indicators)
|
||||||
|
@ -183,7 +184,7 @@ Search keyword and option completion scripts for Bash, Fish and Zsh can be found
|
||||||
#### Cmdline options
|
#### 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]
|
[-p file] [-S] [-v] [-h] [PATH]
|
||||||
|
|
||||||
The missing terminal file manager for X.
|
The missing terminal file manager for X.
|
||||||
|
@ -193,7 +194,7 @@ positional args:
|
||||||
|
|
||||||
optional args:
|
optional args:
|
||||||
-b key bookmark key to open
|
-b key bookmark key to open
|
||||||
-c N dir color, disables if N>7
|
-C disable directory color
|
||||||
-e use exiftool instead of mediainfo
|
-e use exiftool instead of mediainfo
|
||||||
-i start in navigate-as-you-type mode
|
-i start in navigate-as-you-type mode
|
||||||
-l start in light mode
|
-l start in light mode
|
||||||
|
@ -273,6 +274,13 @@ The first time a context is entered, it copies the state of the last visited con
|
||||||
|
|
||||||
When a context is quit, the next active context is selected. If the last active context is quit, the program quits.
|
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
|
||||||
|
|
||||||
Filters support regexes to instantly (search-as-you-type) list the matching entries in the current directory.
|
Filters support regexes to instantly (search-as-you-type) list the matching entries in the current directory.
|
||||||
|
|
14
nnn.1
14
nnn.1
|
@ -7,7 +7,7 @@
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.Nm
|
.Nm
|
||||||
.Op Ar -b key
|
.Op Ar -b key
|
||||||
.Op Ar -c N
|
.Op Ar -C
|
||||||
.Op Ar -e
|
.Op Ar -e
|
||||||
.Op Ar -i
|
.Op Ar -i
|
||||||
.Op Ar -l
|
.Op Ar -l
|
||||||
|
@ -166,9 +166,8 @@ supports the following options:
|
||||||
.Fl "b key"
|
.Fl "b key"
|
||||||
specify bookmark key to open
|
specify bookmark key to open
|
||||||
.Pp
|
.Pp
|
||||||
.Fl "c N"
|
.Fl C
|
||||||
specify dir color (default blue), disables if N>7
|
disable directory color
|
||||||
0-black, 1-red, 2-green, 3-yellow, 4-blue, 5-magenta, 6-cyan, 7-white
|
|
||||||
.Pp
|
.Pp
|
||||||
.Fl e
|
.Fl e
|
||||||
use exiftool instead of mediainfo
|
use exiftool instead of mediainfo
|
||||||
|
@ -282,6 +281,13 @@ files.
|
||||||
export NNN_USE_EDITOR=1
|
export NNN_USE_EDITOR=1
|
||||||
.Ed
|
.Ed
|
||||||
.Pp
|
.Pp
|
||||||
|
\fBNNN_CONTEXT_COLORS:\fR string of color codes for each context, e.g.:
|
||||||
|
.Bd -literal
|
||||||
|
export NNN_CONTEXT_COLORS="1234"
|
||||||
|
|
||||||
|
codes: 0-black, 1-red, 2-green, 3-yellow, 4-blue (default), 5-magenta, 6-cyan, 7-white
|
||||||
|
.Ed
|
||||||
|
.Pp
|
||||||
\fBNNN_IDLE_TIMEOUT:\fR set idle timeout (in seconds) to invoke terminal locker.
|
\fBNNN_IDLE_TIMEOUT:\fR set idle timeout (in seconds) to invoke terminal locker.
|
||||||
.Pp
|
.Pp
|
||||||
\fBNNN_COPIER:\fR set to a clipboard copier script.
|
\fBNNN_COPIER:\fR set to a clipboard copier script.
|
||||||
|
|
60
src/nnn.c
60
src/nnn.c
|
@ -180,7 +180,7 @@ disabledbg()
|
||||||
#define SYMLINK_TO_DIR 0x1
|
#define SYMLINK_TO_DIR 0x1
|
||||||
#define MAX_HOME_LEN 64
|
#define MAX_HOME_LEN 64
|
||||||
#define MAX_CTX 4
|
#define MAX_CTX 4
|
||||||
#define DOT_FILTER_LEN 8
|
#define DOT_FILTER_LEN 7
|
||||||
|
|
||||||
/* Macros to define process spawn behaviour as flags */
|
/* Macros to define process spawn behaviour as flags */
|
||||||
#define F_NONE 0x00 /* no flag set */
|
#define F_NONE 0x00 /* no flag set */
|
||||||
|
@ -258,9 +258,8 @@ typedef struct {
|
||||||
uint showcolor : 1; /* Set to show dirs in blue */
|
uint showcolor : 1; /* Set to show dirs in blue */
|
||||||
uint dircolor : 1; /* Current status of dir color */
|
uint dircolor : 1; /* Current status of dir color */
|
||||||
uint metaviewer : 1; /* Index of metadata viewer in utils[] */
|
uint metaviewer : 1; /* Index of metadata viewer in utils[] */
|
||||||
uint color : 3; /* Color code for directories */
|
|
||||||
uint ctxactive : 1; /* Context active or not */
|
uint ctxactive : 1; /* Context active or not */
|
||||||
uint reserved : 10;
|
uint reserved : 13;
|
||||||
/* The following settings are global */
|
/* The following settings are global */
|
||||||
uint curctx : 2; /* Current context number */
|
uint curctx : 2; /* Current context number */
|
||||||
uint picker : 1; /* Write selection to user-specified file */
|
uint picker : 1; /* Write selection to user-specified file */
|
||||||
|
@ -277,12 +276,13 @@ typedef struct {
|
||||||
char c_name[NAME_MAX + 1]; /* Current file name */
|
char c_name[NAME_MAX + 1]; /* Current file name */
|
||||||
settings c_cfg; /* Current configuration */
|
settings c_cfg; /* Current configuration */
|
||||||
char c_fltr[DOT_FILTER_LEN]; /* Hidden filter */
|
char c_fltr[DOT_FILTER_LEN]; /* Hidden filter */
|
||||||
|
char color; /* Color code for directories */
|
||||||
} context;
|
} context;
|
||||||
|
|
||||||
/* GLOBALS */
|
/* GLOBALS */
|
||||||
|
|
||||||
/* Configuration, contexts */
|
/* 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 context g_ctx[MAX_CTX] __attribute__ ((aligned));
|
||||||
|
|
||||||
static struct entry *dents;
|
static struct entry *dents;
|
||||||
|
@ -798,8 +798,12 @@ static void initcurses(void)
|
||||||
curs_set(FALSE); /* Hide cursor */
|
curs_set(FALSE); /* Hide cursor */
|
||||||
start_color();
|
start_color();
|
||||||
use_default_colors();
|
use_default_colors();
|
||||||
if (cfg.showcolor)
|
if (cfg.showcolor) {
|
||||||
init_pair(1, cfg.color, -1);
|
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 */
|
settimeout(); /* One second */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1518,7 +1522,7 @@ static char *get_bm_loc(int key, char *buf)
|
||||||
static void resetdircolor(mode_t mode)
|
static void resetdircolor(mode_t mode)
|
||||||
{
|
{
|
||||||
if (cfg.dircolor && !S_ISDIR(mode)) {
|
if (cfg.dircolor && !S_ISDIR(mode)) {
|
||||||
attroff(COLOR_PAIR(1) | A_BOLD);
|
attroff(COLOR_PAIR(cfg.curctx + 1) | A_BOLD);
|
||||||
cfg.dircolor = 0;
|
cfg.dircolor = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2103,6 +2107,8 @@ static int show_help(char *path)
|
||||||
|
|
||||||
if (cfg.useeditor)
|
if (cfg.useeditor)
|
||||||
dprintf(fd, "NNN_USE_EDITOR: 1\n");
|
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)
|
if (idletimeout)
|
||||||
dprintf(fd, "NNN_IDLE_TIMEOUT: %d secs\n", idletimeout);
|
dprintf(fd, "NNN_IDLE_TIMEOUT: %d secs\n", idletimeout);
|
||||||
if (copier)
|
if (copier)
|
||||||
|
@ -2478,7 +2484,7 @@ static void redraw(char *path)
|
||||||
ncols -= 5;
|
ncols -= 5;
|
||||||
|
|
||||||
if (cfg.showcolor) {
|
if (cfg.showcolor) {
|
||||||
attron(COLOR_PAIR(1) | A_BOLD);
|
attron(COLOR_PAIR(cfg.curctx + 1) | A_BOLD);
|
||||||
cfg.dircolor = 1;
|
cfg.dircolor = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2500,7 +2506,7 @@ static void redraw(char *path)
|
||||||
|
|
||||||
/* Must reset e.g. no files in dir */
|
/* Must reset e.g. no files in dir */
|
||||||
if (cfg.dircolor) {
|
if (cfg.dircolor) {
|
||||||
attroff(COLOR_PAIR(1) | A_BOLD);
|
attroff(COLOR_PAIR(cfg.curctx + 1) | A_BOLD);
|
||||||
cfg.dircolor = 0;
|
cfg.dircolor = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3511,14 +3517,14 @@ nochange:
|
||||||
static void usage(void)
|
static void usage(void)
|
||||||
{
|
{
|
||||||
fprintf(stdout,
|
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"
|
" [-p file] [-S] [-v] [-h] [PATH]\n\n"
|
||||||
"The missing terminal file manager for X.\n\n"
|
"The missing terminal file manager for X.\n\n"
|
||||||
"positional args:\n"
|
"positional args:\n"
|
||||||
" PATH start dir [default: current dir]\n\n"
|
" PATH start dir [default: current dir]\n\n"
|
||||||
"optional args:\n"
|
"optional args:\n"
|
||||||
" -b key bookmark key to open\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"
|
" -e use exiftool instead of mediainfo\n"
|
||||||
" -i start in navigate-as-you-type mode\n"
|
" -i start in navigate-as-you-type mode\n"
|
||||||
" -l start in light mode\n"
|
" -l start in light mode\n"
|
||||||
|
@ -3541,7 +3547,7 @@ int main(int argc, char *argv[])
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((opt = getopt(argc, argv, "Slib:c:ep:vh")) != -1) {
|
while ((opt = getopt(argc, argv, "Slib:Cep:vh")) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'S':
|
case 'S':
|
||||||
cfg.blkorder = 1;
|
cfg.blkorder = 1;
|
||||||
|
@ -3558,11 +3564,8 @@ int main(int argc, char *argv[])
|
||||||
case 'b':
|
case 'b':
|
||||||
ipath = optarg;
|
ipath = optarg;
|
||||||
break;
|
break;
|
||||||
case 'c':
|
case 'C':
|
||||||
if (atoi(optarg) > 7)
|
|
||||||
cfg.showcolor = 0;
|
cfg.showcolor = 0;
|
||||||
else
|
|
||||||
cfg.color = (uchar)atoi(optarg);
|
|
||||||
break;
|
break;
|
||||||
case 'e':
|
case 'e':
|
||||||
cfg.metaviewer = EXIFTOOL;
|
cfg.metaviewer = EXIFTOOL;
|
||||||
|
@ -3592,6 +3595,31 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 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 */
|
/* Parse bookmarks string */
|
||||||
if (parsebmstr() < 0) {
|
if (parsebmstr() < 0) {
|
||||||
fprintf(stderr, "ERROR parsing NNN_BMS: set single-char bookmark keys only\n");
|
fprintf(stderr, "ERROR parsing NNN_BMS: set single-char bookmark keys only\n");
|
||||||
|
|
Loading…
Reference in a new issue