@@ -59,8 +59,9 @@ Have fun with it! Missing a feature? Want to contribute? Head to the rolling [To | |||||
- [add bookmarks](#add-bookmarks) | - [add bookmarks](#add-bookmarks) | ||||
- [use cd .....](#use-cd-) | - [use cd .....](#use-cd-) | ||||
- [cd on quit](#cd-on-quit) | - [cd on quit](#cd-on-quit) | ||||
- [copy file paths to clipboard](#copy-file-paths-to-clipboard) | |||||
- [copy file paths when X is missing](#copy-file-paths-when-x-is-missing) | |||||
- [copy file paths](#copy-file-paths) | |||||
- [to clipboard](#to-clipboard) | |||||
- [when X is missing](#when-x-is-missing) | |||||
- [run custom scripts](#run-custom-scripts) | - [run custom scripts](#run-custom-scripts) | ||||
- [sample scripts](#sample-scripts) | - [sample scripts](#sample-scripts) | ||||
- [dual-pane or multi-pane](#dual-pane-or-multi-pane) | - [dual-pane or multi-pane](#dual-pane-or-multi-pane) | ||||
@@ -248,6 +249,7 @@ optional args: | |||||
^F Extract archive | ^F Extract archive | ||||
Space, ^K Copy file path | Space, ^K Copy file path | ||||
^Y Toggle multi-copy | ^Y Toggle multi-copy | ||||
y Show copy buffer | |||||
^T Toggle path quote | ^T Toggle path quote | ||||
^L Redraw, clear prompt | ^L Redraw, clear prompt | ||||
L Lock terminal | L Lock terminal | ||||
@@ -359,7 +361,11 @@ Pick the appropriate file for your shell from [`scripts/quitcd`](scripts/quitcd) | |||||
As you might notice, `nnn` uses the environment variable `NNN_TMPFILE` to write the last visited directory path. You can change it. | As you might notice, `nnn` uses the environment variable `NNN_TMPFILE` to write the last visited directory path. You can change it. | ||||
#### copy file paths to clipboard | |||||
#### copy file paths | |||||
File paths can be copied to the clipboard or to a specific temporary file (if X is unavailable, for example). When in multi-copy mode, currently copied file paths can be listed by pressing `y`. | |||||
##### to clipboard | |||||
`nnn` can pipe the absolute path of the current file or multiple files to a copier script. For example, you can use `xsel` on Linux or `pbcopy` on OS X. | `nnn` can pipe the absolute path of the current file or multiple files to a copier script. For example, you can use `xsel` on Linux or `pbcopy` on OS X. | ||||
@@ -392,7 +398,7 @@ This is particularly useful if you are planning to copy the whole string to the | |||||
Note that the filename is not escaped. So copying may still fail for filenames having quote(s) in them. | 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 | |||||
##### 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 `DIR/.nnncp`, where `DIR` (by priority) is: | 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 `DIR/.nnncp`, where `DIR` (by priority) is: | ||||
@@ -111,6 +111,8 @@ Extract archive in current directory | |||||
Invoke file path copier | Invoke file path copier | ||||
.It Ic ^Y | .It Ic ^Y | ||||
Toggle multiple file path copy mode | Toggle multiple file path copy mode | ||||
.It Ic y | |||||
Show copy buffer | |||||
.It Ic ^T | .It Ic ^T | ||||
Toggle path quote | Toggle path quote | ||||
.It Ic ^L | .It Ic ^L | ||||
@@ -351,6 +351,7 @@ static const char messages[][16] = { | |||||
/* Forward declarations */ | /* Forward declarations */ | ||||
static void redraw(char *path); | static void redraw(char *path); | ||||
static char * get_output(char *buf, size_t bytes, char *file, char *arg1, char *arg2, int pager); | |||||
/* Functions */ | /* Functions */ | ||||
@@ -674,6 +675,36 @@ appendfpath(const char *path, const size_t len) | |||||
return TRUE; | return TRUE; | ||||
} | } | ||||
static bool | |||||
showcplist() | |||||
{ | |||||
ssize_t len; | |||||
if (!copybufpos) | |||||
return FALSE; | |||||
if (g_tmpfpath[0]) | |||||
xstrlcpy(g_tmpfpath + g_tmpfplen - 1, "/.nnnXXXXXX", MAX_HOME_LEN - g_tmpfplen); | |||||
else { | |||||
printmsg(messages[STR_NOHOME_ID]); | |||||
return -1; | |||||
} | |||||
int fd = mkstemp(g_tmpfpath); | |||||
if (fd == -1) | |||||
return FALSE; | |||||
len = write(fd, pcopybuf, copybufpos - 1); | |||||
close(fd); | |||||
exitcurses(); | |||||
if (len == copybufpos - 1) | |||||
get_output(NULL, 0, "cat", g_tmpfpath, NULL, 1); | |||||
unlink(g_tmpfpath); | |||||
refresh(); | |||||
return TRUE; | |||||
} | |||||
/* | /* | ||||
* Return number of dots if all chars in a string are dots, else 0 | * Return number of dots if all chars in a string are dots, else 0 | ||||
*/ | */ | ||||
@@ -1992,6 +2023,7 @@ show_help(char *path) | |||||
"d^F Extract archive\n" | "d^F Extract archive\n" | ||||
"6Space, ^K Copy file path\n" | "6Space, ^K Copy file path\n" | ||||
"d^Y Toggle multi-copy\n" | "d^Y Toggle multi-copy\n" | ||||
"ey Show copy buffer\n" | |||||
"d^T Toggle path quote\n" | "d^T Toggle path quote\n" | ||||
"d^L Redraw, clear prompt\n" | "d^L Redraw, clear prompt\n" | ||||
"eL Lock terminal\n" | "eL Lock terminal\n" | ||||
@@ -3104,6 +3136,12 @@ nochange: | |||||
} else | } else | ||||
printmsg("multi-copy off"); | printmsg("multi-copy off"); | ||||
goto nochange; | goto nochange; | ||||
case SEL_COPYLIST: | |||||
if (cfg.copymode) | |||||
showcplist(); | |||||
else | |||||
printmsg("multi-copy off"); | |||||
goto nochange; | |||||
case SEL_QUOTE: | case SEL_QUOTE: | ||||
cfg.quote ^= 1; | cfg.quote ^= 1; | ||||
DPRINTF_D(cfg.quote); | DPRINTF_D(cfg.quote); | ||||
@@ -66,6 +66,7 @@ enum action { | |||||
SEL_REDRAW, | SEL_REDRAW, | ||||
SEL_COPY, | SEL_COPY, | ||||
SEL_COPYMUL, | SEL_COPYMUL, | ||||
SEL_COPYLIST, | |||||
SEL_QUOTE, | SEL_QUOTE, | ||||
SEL_OPEN, | SEL_OPEN, | ||||
SEL_NEW, | SEL_NEW, | ||||
@@ -188,6 +189,8 @@ static struct key bindings[] = { | |||||
{ ' ', SEL_COPY, "", "" }, | { ' ', SEL_COPY, "", "" }, | ||||
/* Toggle copy multiple file paths */ | /* Toggle copy multiple file paths */ | ||||
{ CONTROL('Y'), SEL_COPYMUL, "", "" }, | { CONTROL('Y'), SEL_COPYMUL, "", "" }, | ||||
/* Show list of copied files */ | |||||
{ 'y', SEL_COPYLIST, "", "" }, | |||||
/* Toggle quote on while copy */ | /* Toggle quote on while copy */ | ||||
{ CONTROL('T'), SEL_QUOTE, "", "" }, | { CONTROL('T'), SEL_QUOTE, "", "" }, | ||||
/* Open in a custom application */ | /* Open in a custom application */ | ||||