@@ -391,7 +391,7 @@ Note that the filename is not escaped. So copying may still fail for filenames h | |||||
#### copy file paths when X is missing | #### copy file paths when X is missing | ||||
A very common scenario on headless remote servers connected via SSH. As the clipboard is missing, `nnn` copies the path names to the tmp file `/tmp/nnncp$USER`. | |||||
A very common scenario on headless remote servers connected via SSH. As the clipboard is missing, `nnn` copies the path names to the tmp file `$HOME/.nnncp`. | |||||
`nnn` needs to know X is unavailable: | `nnn` needs to know X is unavailable: | ||||
@@ -400,15 +400,15 @@ A very common scenario on headless remote servers connected via SSH. As the clip | |||||
Use <kbd>^Y</kbd> and/or <kbd>^K</kbd> to copy file paths as usual. To use the copied paths from the cmdline, use command substitution: | Use <kbd>^Y</kbd> and/or <kbd>^K</kbd> to copy file paths as usual. To use the copied paths from the cmdline, use command substitution: | ||||
# bash/zsh | # bash/zsh | ||||
ls -ltr `cat /tmp/nnncpuser` | |||||
ls -ltr $(cat /tmp/nnncpuser) | |||||
ls -ltr `cat /home/user/.nnncp` | |||||
ls -ltr $(cat /home/user/.nnncp) | |||||
# fish | # fish | ||||
ls -ltr (cat /tmp/nnncpuser) | |||||
ls -ltr (cat /home/user/.nnncp) | |||||
An alias may be handy: | An alias may be handy: | ||||
alias ncp='cat /tmp/nnncpuser' | |||||
alias ncp='cat /home/user/.nnncp' | |||||
so you can - | so you can - | ||||
@@ -257,7 +257,7 @@ screensaver. | |||||
------------------------------------- | ------------------------------------- | ||||
.Ed | .Ed | ||||
.Pp | .Pp | ||||
\fBNNN_NO_X:\fR X display is unavailable. Copy file path(s) to \fI/tmp/nnncp$USER\fR. | |||||
\fBNNN_NO_X:\fR X display is unavailable. Copy file path(s) to \fI$HOME/.nnncp\fR. | |||||
.Bd -literal | .Bd -literal | ||||
export NNN_NO_X=1 | export NNN_NO_X=1 | ||||
.Ed | .Ed | ||||
@@ -391,6 +391,8 @@ printerr(int linenum) | |||||
{ | { | ||||
exitcurses(); | exitcurses(); | ||||
fprintf(stderr, "line %d: (%d) %s\n", linenum, errno, strerror(errno)); | fprintf(stderr, "line %d: (%d) %s\n", linenum, errno, strerror(errno)); | ||||
if (cfg.noxdisplay) | |||||
unlink(g_cppath); | |||||
exit(1); | exit(1); | ||||
} | } | ||||
@@ -608,21 +610,11 @@ writecp(const char *buf, const size_t buflen) | |||||
{ | { | ||||
FILE *fp = fopen(g_cppath, "w"); | FILE *fp = fopen(g_cppath, "w"); | ||||
if (!fp) { | |||||
struct passwd *pass = getpwuid(getuid()); | |||||
xstrlcpy(g_cppath, "./nnncp", 11); | |||||
xstrlcpy(g_cppath + 10, pass->pw_name, 33); | |||||
fp = fopen(g_cppath, "w"); | |||||
if (!fp) | |||||
printwarn(); | |||||
} | |||||
if (fp) { | if (fp) { | ||||
fwrite(buf, 1, buflen, fp); | fwrite(buf, 1, buflen, fp); | ||||
fclose(fp); | fclose(fp); | ||||
} | |||||
} else | |||||
printwarn(); | |||||
} | } | ||||
static bool | static bool | ||||
@@ -3431,11 +3423,8 @@ main(int argc, char *argv[]) | |||||
/* Check if X11 is available */ | /* Check if X11 is available */ | ||||
if (getenv("NNN_NO_X")) { | if (getenv("NNN_NO_X")) { | ||||
cfg.noxdisplay = 1; | cfg.noxdisplay = 1; | ||||
struct passwd *pass = getpwuid(getuid()); | |||||
xstrlcpy(g_cppath, "/tmp/nnncp", 11); | |||||
xstrlcpy(g_cppath + 10, pass->pw_name, 33); | |||||
size_t len = xstrlcpy(g_cppath, getenv("HOME"), 48); | |||||
xstrlcpy(g_cppath + len - 1, "/.nnncp", 48 - len); | |||||
} | } | ||||
signal(SIGINT, SIG_IGN); | signal(SIGINT, SIG_IGN); | ||||
@@ -3457,6 +3446,9 @@ main(int argc, char *argv[]) | |||||
browse(ipath, ifilter); | browse(ipath, ifilter); | ||||
exitcurses(); | exitcurses(); | ||||
if (cfg.noxdisplay) | |||||
unlink(g_cppath); | |||||
#ifdef LINUX_INOTIFY | #ifdef LINUX_INOTIFY | ||||
/* Shutdown inotify */ | /* Shutdown inotify */ | ||||
if (inotify_wd >= 0) | if (inotify_wd >= 0) | ||||