README.md | 10 +++++-----
nnn.1 | 2 +-
nnn.c | 15 ++++++++++-----
diff --git a/README.md b/README.md
index 105481a65465c5e0d21bc2c5ad03eae73535fdf4..7459a260772d1b528ece46bebcd24859cf76540a 100644
--- a/README.md
+++ b/README.md
@@ -385,7 +385,7 @@ This is particularly useful if you are planning to copy the whole string to the shell to run a command. Quotes can be toggled at runtime using ^T.
#### 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`.
+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`.
`nnn` needs to know X is unavailable:
@@ -394,15 +394,15 @@
Use ^Y and/or ^K to copy file paths as usual. To use the copied paths from the cmdline, use command substitution:
# bash/zsh
- ls -ltr `cat /tmp/nnncp`
- ls -ltr $(cat /tmp/nnncp)
+ ls -ltr `cat /tmp/nnncpuser`
+ ls -ltr $(cat /tmp/nnncpuser)
# fish
- ls -ltr (cat /tmp/nnncp)
+ ls -ltr (cat /tmp/nnncpuser)
An alias may be handy:
- alias ncp='cat /tmp/nnncp'
+ alias ncp='cat /tmp/nnncpuser'
so you can -
diff --git a/nnn.1 b/nnn.1
index 533f70dd4f204c9b6e1f4bacc2418c1f26289beb..db0e8de329ed9f287ed8af1e3cd263535ec8afca 100644
--- a/nnn.1
+++ b/nnn.1
@@ -248,7 +248,7 @@ echo -n $1 | xsel --clipboard --input
-------------------------------------
.Ed
.Pp
-\fBNNN_NO_X:\fR X display is unavailable. Copy file path(s) to \fI/tmp/nnncp\fR.
+\fBNNN_NO_X:\fR X display is unavailable. Copy file path(s) to \fI/tmp/nnncp$USER\fR.
.Bd -literal
export NNN_NO_X=1
.Ed
diff --git a/nnn.c b/nnn.c
index 3f186ebc932ecab2ccccc2f3ffe82b6c794ffc23..0c4c695e1755a72240acf50de95c46bb34922d33 100644
--- a/nnn.c
+++ b/nnn.c
@@ -195,9 +195,6 @@ #define NUM_EVENT_SLOTS 1
#define NUM_EVENT_FDS 1
#endif
-/* File path to copy file names when X is not available */
-#define TMP_CP_PATH "/tmp/nnncp"
-
/* TYPE DEFINITIONS */
typedef unsigned long ulong;
typedef unsigned int uint;
@@ -316,6 +313,9 @@ };
/* For use in functions which are isolated and don't return the buffer */
static char g_buf[MAX_CMD_LEN] __attribute__ ((aligned));
+
+/* Buffer for file path copy file */
+static char g_cppath[48] __attribute__ ((aligned));
/* Forward declarations */
static void redraw(char *path);
@@ -635,7 +635,7 @@ /* Writes buflen char(s) from buf to a file */
static void
writecp(const char *buf, const size_t buflen)
{
- FILE *fp = fopen(TMP_CP_PATH, "w");
+ FILE *fp = fopen(g_cppath, "w");
if (fp) {
fwrite(buf, 1, buflen, fp);
@@ -3318,8 +3318,13 @@ if (getenv("NNN_QUOTE_ON"))
cfg.quote = 1;
/* Check if X11 is available */
- if (getenv("NNN_NO_X"))
+ if (getenv("NNN_NO_X")) {
cfg.noxdisplay = 1;
+
+ struct passwd *pass = getpwuid(getuid());
+ xstrlcpy(g_cppath, "/tmp/nnncp", 11);
+ xstrlcpy(g_cppath + 10, pass->pw_name, 33);
+ }
signal(SIGINT, SIG_IGN);