commit fde7d5ff9239788495c5a36c0122084224c7754e
parent e7ebda48a29fcfbc5d67473988514809d9427953
Author: Arun Prakash Jana <engineerarun@gmail.com>
Date: Sun, 8 Feb 2026 09:16:27 +0530
Copy and move from system clipboard to current directory
Diffstat:
2 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/README.md b/README.md
@@ -95,6 +95,7 @@ Runs on the Pi, [Termux](https://www.youtube.com/embed/AbaauM7gUJw) (Android), L
- Batch renamer for selection or dir
- List input stream of file paths from stdin or plugin
- Copy (as), move (as), delete, archive, link selection
+ - Easily copy, move paths in system clipboard to current dir
- Dir updates, notification on `cp`, `mv`, `rm` completion
- Copy file paths to system clipboard on select
- Launch apps, run commands, spawn a shell, toggle exe
diff --git a/src/nnn.c b/src/nnn.c
@@ -2107,7 +2107,7 @@ static void endselection(bool endselmode)
}
/* Returns: 1 - success, 0 - none selected, -1 - other failure */
-static int editselection(void)
+static int editselection(bool allowemptysel)
{
int ret = -1;
int fd, lines = 0;
@@ -2115,7 +2115,7 @@ static int editselection(void)
struct stat sb;
time_t mtime;
- if (!selbufpos) /* External selection is only editable at source */
+ if (!allowemptysel && !selbufpos) /* External selection is only editable at source */
return listselfile();
fd = create_tmp_file();
@@ -2124,7 +2124,8 @@ static int editselection(void)
return -1;
}
- seltofile(fd, NULL, NEWLINE);
+ if (!allowemptysel)
+ seltofile(fd, NULL, NEWLINE);
if (close(fd)) {
DPRINTF_S(strerror(errno));
return -1;
@@ -2165,7 +2166,9 @@ static int editselection(void)
return 1;
}
- if (sb.st_size > selbufpos) {
+ if (allowemptysel)
+ selbufrealloc(sb.st_size);
+ else if (sb.st_size > selbufpos) {
DPRINTF_S("edited buffer larger than previous");
if (unlink(g_tmpfpath)) {
DPRINTF_S(strerror(errno));
@@ -2211,7 +2214,7 @@ static int editselection(void)
/* Add a line for the last file */
++lines;
- if (lines > nselected) {
+ if (!allowemptysel && (lines > nselected)) {
DPRINTF_S("files added to selection");
goto emptyedit;
}
@@ -2750,6 +2753,9 @@ static bool cpmvrm_selection(enum action sel, char *path)
{
int r;
+ if ((sel == SEL_CP || sel == SEL_MV) && isselfileempty())
+ editselection(TRUE);
+
if (isselfileempty()) {
if (nselected)
clearselection();
@@ -8576,7 +8582,7 @@ nochange:
#endif
continue;
case SEL_SELEDIT:
- r = editselection();
+ r = editselection(FALSE);
if (r <= 0) {
r = !r ? MSG_0_SELECTED : MSG_FAILED;
printwait(messages[r], &presel);