README.md | 2 +- nnn.1 | 17 ++++++++++------- nnn.c | 52 +++++++++++++++++++++++++++++++++++++++++++--------- diff --git a/README.md b/README.md index 4ebec8ba6fee53a3e1926299ea614518105f52bd..ae36f60787b14ce63201b8eca6f04e724725cd2a 100644 --- a/README.md +++ b/README.md @@ -182,7 +182,7 @@ o | Open dir in NNN_DE_FILE_MANAGER p | Open entry in PAGER (fallback less) ^K | Invoke file path copier ^L | Force a redraw, exit filter prompt - ? | Toggle help screen + ? | Toggle help and settings screen Q | Quit and change directory q, ^Q | Quit ``` diff --git a/nnn.1 b/nnn.1 index e73ecd5bec3e938b2653e6c3a86da4219d5e0557..303d630205e50f805f0ee4997aac811007b85392 100644 --- a/nnn.1 +++ b/nnn.1 @@ -88,7 +88,7 @@ Invoke file path copier .It Ic ^L Force a redraw, exit filter prompt .It Ic \&? -Toggle help screen +Toggle help and settings screen .It Ic Q Quit and change directory .It Ic q, ^Q @@ -129,6 +129,9 @@ at: .br .Em https://github.com/jarun/nnn/wiki/all-about-nlay .Pp +There is no configuration file. Settings work on environment variables. Please +refer to the ENVIRONMENT section below. +.Pp Configuring .Nm to change to the last visited directory on quit requires shell integration in a @@ -158,16 +161,16 @@ .Sh ENVIRONMENT The SHELL, EDITOR and PAGER environment variables take precedence when dealing with the !, e and p commands respectively. .Pp +\fBNNN_BMS:\fR bookmark string as \fIkey:location\fR pairs (max 10) separated by +\fI;\fR: +.Bd -literal + export NNN_BMS='doc:~/Documents;u:/home/user/Cam Uploads;D:~/Downloads/' +.Ed +.Pp \fBNNN_USE_EDITOR:\fR use EDITOR (preferably CLI, fallback vi) to handle text files. .Bd -literal export NNN_USE_EDITOR=1 -.Ed -.Pp -\fBNNN_BMS:\fR bookmark string as \fIkey:location\fR pairs (max 10) separated by -\fI;\fR: -.Bd -literal - export NNN_BMS='doc:~/Documents;u:/home/user/Cam Uploads;D:~/Downloads/' .Ed .Pp \fBNNN_DE_FILE_MANAGER:\fR set to a desktop file manager to open the current diff --git a/nnn.c b/nnn.c index 0956b06f01d7d7abdc578d95025fdd1068489396..23eaa430ecf9b74090311422eb4520e1eaec91a6 100644 --- a/nnn.c +++ b/nnn.c @@ -1311,7 +1311,12 @@ static int show_help(void) { - static char helpstr[] = ("echo \"\ + char tmp[] = "/tmp/nnnXXXXXX"; + int fd = mkstemp(tmp); + if (fd == -1) + return -1; + + static char helpstr[] = ("\ Key | Function\n\ -+-\n\ Up, k, ^P | Previous entry\n\ @@ -1344,11 +1349,40 @@ o | Open dir in NNN_DE_FILE_MANAGER\n\ p | Open entry in PAGER (fallback less)\n\ ^K | Invoke file path copier\n\ ^L | Force a redraw, exit filter prompt\n\ - ? | Toggle help screen\n\ + ? | Toggle help and settings screen\n\ Q | Quit and change directory\n\ - q, ^Q | Quit\n\n\" | less"); + q, ^Q | Quit\n\n\n"); + + dprintf(fd, "%s", helpstr); - return system(helpstr); + if (getenv("NNN_BMS")) { + dprintf(fd, "BOOKMARKS\n"); + for (int i = 0; i < MAX_BM; i++) + if (bookmark[i].key) + dprintf(fd, " %s: %s\n", bookmark[i].key, bookmark[i].loc); + else + break; + dprintf(fd, "\n"); + } + + if (editor) + dprintf(fd, "NNN_USE_EDITOR: %s\n", editor); + + if (desktop_manager) + dprintf(fd, "NNN_DE_FILE_MANAGER: %s\n", desktop_manager); + + if (idletimeout) + dprintf(fd, "NNN_IDLE_TIMEOUT: %d secs\n", idletimeout); + + if (copier) + dprintf(fd, "NNN_COPIER: %s\n", copier); + + dprintf(fd, "\n"); + close(fd); + + get_output(NULL, 0, "cat", tmp, NULL, 1); + unlink(tmp); + return 0; } static int @@ -2285,6 +2319,11 @@ if (getuid() == 0) showhidden = 1; initfilter(showhidden, &ifilter); + /* Parse bookmarks string, if available */ + char *bms = getenv("NNN_BMS"); + if (bms) + parsebmstr(bms); + /* Edit text in EDITOR, if opted */ if (getenv("NNN_USE_EDITOR")) editor = xgetenv("EDITOR", "vi"); @@ -2303,11 +2342,6 @@ idletimeout = abs(atoi(copier)); /* Get the default copier, if set */ copier = getenv("NNN_COPIER"); - - /* Parse bookmarks string, if available */ - char *bms = getenv("NNN_BMS"); - if (bms) - parsebmstr(bms); signal(SIGINT, SIG_IGN);