export NNN_QUOTE_ON=1
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 <kbd>^T</kbd>.
+Note that the filename is not escaped. So copying may still fail for filenames having quote(s) in them.
+
#### 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`.
.Ed
.Pp
\fBNNN_QUOTE_ON:\fR wrap copied paths within single quotes. Useful for pasting
-names in the shell.
+names in the shell. Note that the filename is not escaped. So copying may still fail
+for filenames having quote(s) in them.
.Pp
\fBNNN_SCRIPT:\fR path to a custom script to invoke with currently selected file name as argument 1.
.Bd -literal
return grp->gr_name;
}
+static bool
+istgtdir(const char *tgtpath)
+{
+ if (tgtpath) {
+ struct stat tgtsb;
+ int r = stat(tgtpath, &tgtsb);
+ if ((r == 0) && (tgtsb.st_mode & S_IFMT) == S_IFDIR)
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
/*
* Follows the stat(1) output closely
*/
/* Show file name or 'symlink' -> 'target' */
if (perms[0] == 'l') {
/* Note that MAX_CMD_LEN > PATH_MAX */
- ssize_t len = readlink(fpath, g_buf, MAX_CMD_LEN);
-
- if (len != -1) {
- g_buf[len] = '\0';
+ char *tgt = realpath(fpath, g_buf);
+ if (tgt) {
+ char ch[] = {'\'', '\0', '\0'};
+ if (istgtdir(g_buf)) {
+ ch[1] = ch[0];
+ ch[0] = '/';
+ }
/*
* We pass g_buf but unescape() operates on g_buf too!
* Read the API notes for information on how this works.
*/
- dprintf(fd, " -> '%s'", unescape(g_buf, 0));
+ dprintf(fd, " -> '%s%s", unescape(g_buf, 0), ch);
}
}