mirror of
https://github.com/jarun/nnn.git
synced 2024-12-01 02:49:44 +00:00
Fix #89: User-specific tmp file for copying filenames
Use distinct (by username) tmp filename to copy file paths. The pattern used is: /tmp/nnncp$USER If username is 'arun', the file name is `/tmp/nnncparun`.
This commit is contained in:
parent
43134cdfa8
commit
3036b8a733
10
README.md
10
README.md
|
@ -385,7 +385,7 @@ This is particularly useful if you are planning to copy the whole string to the
|
|||
|
||||
#### 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 @@ 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:
|
||||
|
||||
# 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 -
|
||||
|
||||
|
|
2
nnn.1
2
nnn.1
|
@ -248,7 +248,7 @@ screensaver.
|
|||
-------------------------------------
|
||||
.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
|
||||
|
|
15
nnn.c
15
nnn.c
|
@ -195,9 +195,6 @@ disabledbg()
|
|||
#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;
|
||||
|
@ -317,6 +314,9 @@ static const char messages[][16] =
|
|||
/* 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 @@ xbasename(char *path)
|
|||
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,9 +3318,14 @@ main(int argc, char *argv[])
|
|||
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);
|
||||
|
||||
/* Test initial path */
|
||||
|
|
Loading…
Reference in a new issue