mirror of
https://github.com/jarun/nnn.git
synced 2025-02-26 03:01:32 +00:00
Support file path quote on copy
This commit is contained in:
parent
ff502f0b3e
commit
6da9d5f499
4 changed files with 45 additions and 3 deletions
|
@ -247,6 +247,7 @@ optional arguments:
|
||||||
^F | Extract archive
|
^F | Extract archive
|
||||||
^K | Invoke file path copier
|
^K | Invoke file path copier
|
||||||
^Y | Toggle multi-copy mode
|
^Y | Toggle multi-copy mode
|
||||||
|
^T | Toggle path quote
|
||||||
^L | Redraw, clear prompt
|
^L | Redraw, clear prompt
|
||||||
? | Help, settings
|
? | Help, settings
|
||||||
Q | Quit and cd
|
Q | Quit and cd
|
||||||
|
@ -369,6 +370,11 @@ To copy multiple file paths, switch to the multi-copy mode using <kbd>^Y</kbd>.
|
||||||
|
|
||||||
Pressing <kbd>^Y</kbd> again copies the paths to clipboard and exits the multi-copy mode.
|
Pressing <kbd>^Y</kbd> again copies the paths to clipboard and exits the multi-copy mode.
|
||||||
|
|
||||||
|
To wrap each file path within single quotes, export `NNN_QUOTE_ON`:
|
||||||
|
|
||||||
|
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>.
|
||||||
|
|
||||||
#### change dir color
|
#### change dir color
|
||||||
|
|
||||||
The default color for directories is blue. Option `-c` accepts color codes from 0 to 7 to use a different color:
|
The default color for directories is blue. Option `-c` accepts color codes from 0 to 7 to use a different color:
|
||||||
|
|
5
nnn.1
5
nnn.1
|
@ -104,6 +104,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 ^T
|
||||||
|
Toggle path quote
|
||||||
.It Ic ^L
|
.It Ic ^L
|
||||||
Force a redraw, clear rename or filter prompt
|
Force a redraw, clear rename or filter prompt
|
||||||
.It Ic \&?
|
.It Ic \&?
|
||||||
|
@ -247,6 +249,9 @@ screensaver.
|
||||||
.Bd -literal
|
.Bd -literal
|
||||||
export NNN_NOWAIT=1
|
export NNN_NOWAIT=1
|
||||||
.Ed
|
.Ed
|
||||||
|
.Pp
|
||||||
|
\fBNNN_QUOTE_ON:\fR wrap copied paths within single quotes. Useful for pasting
|
||||||
|
names in the shell.
|
||||||
.Sh KNOWN ISSUES
|
.Sh KNOWN ISSUES
|
||||||
If you are using urxvt you might have to set backspacekey to DEC.
|
If you are using urxvt you might have to set backspacekey to DEC.
|
||||||
.Sh AUTHORS
|
.Sh AUTHORS
|
||||||
|
|
34
nnn.c
34
nnn.c
|
@ -229,13 +229,14 @@ typedef struct {
|
||||||
ushort showcolor : 1; /* Set to show dirs in blue */
|
ushort showcolor : 1; /* Set to show dirs in blue */
|
||||||
ushort dircolor : 1; /* Current status of dir color */
|
ushort dircolor : 1; /* Current status of dir color */
|
||||||
ushort metaviewer : 1; /* Index of metadata viewer in utils[] */
|
ushort metaviewer : 1; /* Index of metadata viewer in utils[] */
|
||||||
|
ushort quote : 1; /* Copy paths within quotes */
|
||||||
ushort color : 3; /* Color code for directories */
|
ushort color : 3; /* Color code for directories */
|
||||||
} settings;
|
} settings;
|
||||||
|
|
||||||
/* GLOBALS */
|
/* GLOBALS */
|
||||||
|
|
||||||
/* Configuration */
|
/* Configuration */
|
||||||
static settings cfg = {0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 4};
|
static settings cfg = {0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 4};
|
||||||
|
|
||||||
static struct entry *dents;
|
static struct entry *dents;
|
||||||
static char *pnamebuf, *pcopybuf;
|
static char *pnamebuf, *pcopybuf;
|
||||||
|
@ -619,7 +620,7 @@ xbasename(char *path)
|
||||||
static bool
|
static bool
|
||||||
appendfilepath(const char *path, const size_t len)
|
appendfilepath(const char *path, const size_t len)
|
||||||
{
|
{
|
||||||
if ((copybufpos >= copybuflen) || (len > (copybuflen - (copybufpos + 1)))) {
|
if ((copybufpos >= copybuflen) || (len > (copybuflen - (copybufpos + 3)))) {
|
||||||
copybuflen += PATH_MAX;
|
copybuflen += PATH_MAX;
|
||||||
pcopybuf = xrealloc(pcopybuf, copybuflen);
|
pcopybuf = xrealloc(pcopybuf, copybuflen);
|
||||||
if (!pcopybuf) {
|
if (!pcopybuf) {
|
||||||
|
@ -628,10 +629,24 @@ appendfilepath(const char *path, const size_t len)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (copybufpos)
|
if (copybufpos) {
|
||||||
pcopybuf[copybufpos - 1] = '\n';
|
pcopybuf[copybufpos - 1] = '\n';
|
||||||
|
if (cfg.quote) {
|
||||||
|
pcopybuf[copybufpos] = '\'';
|
||||||
|
++copybufpos;
|
||||||
|
}
|
||||||
|
} else if (cfg.quote) {
|
||||||
|
pcopybuf[copybufpos] = '\'';
|
||||||
|
++copybufpos;
|
||||||
|
}
|
||||||
|
|
||||||
copybufpos += xstrlcpy(pcopybuf + copybufpos, path, len);
|
copybufpos += xstrlcpy(pcopybuf + copybufpos, path, len);
|
||||||
|
if (cfg.quote) {
|
||||||
|
pcopybuf[copybufpos - 1] = '\'';
|
||||||
|
pcopybuf[copybufpos] = '\0';
|
||||||
|
++copybufpos;
|
||||||
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1844,6 +1859,7 @@ show_help(char *path)
|
||||||
"d^F | Extract archive\n"
|
"d^F | Extract archive\n"
|
||||||
"d^K | Invoke file path copier\n"
|
"d^K | Invoke file path copier\n"
|
||||||
"d^Y | Toggle multi-copy mode\n"
|
"d^Y | Toggle multi-copy mode\n"
|
||||||
|
"d^T | Toggle path quote\n"
|
||||||
"d^L | Redraw, clear prompt\n"
|
"d^L | Redraw, clear prompt\n"
|
||||||
"e? | Help, settings\n"
|
"e? | Help, settings\n"
|
||||||
"eQ | Quit and cd\n"
|
"eQ | Quit and cd\n"
|
||||||
|
@ -2880,6 +2896,14 @@ nochange:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
goto nochange;
|
goto nochange;
|
||||||
|
case SEL_QUOTE:
|
||||||
|
cfg.quote ^= 1;
|
||||||
|
DPRINTF_D(cfg.quote);
|
||||||
|
if (cfg.quote)
|
||||||
|
printmsg("quotes on");
|
||||||
|
else
|
||||||
|
printmsg("quotes off");
|
||||||
|
goto nochange;
|
||||||
case SEL_OPEN:
|
case SEL_OPEN:
|
||||||
printprompt("open with: "); // fallthrough
|
printprompt("open with: "); // fallthrough
|
||||||
case SEL_NEW:
|
case SEL_NEW:
|
||||||
|
@ -3184,6 +3208,10 @@ main(int argc, char *argv[])
|
||||||
/* Get nowait flag */
|
/* Get nowait flag */
|
||||||
nowait |= getenv("NNN_NOWAIT") ? F_NOWAIT : 0;
|
nowait |= getenv("NNN_NOWAIT") ? F_NOWAIT : 0;
|
||||||
|
|
||||||
|
/* Enable quotes if opted */
|
||||||
|
if (getenv("NNN_QUOTE_ON"))
|
||||||
|
cfg.quote = 1;
|
||||||
|
|
||||||
signal(SIGINT, SIG_IGN);
|
signal(SIGINT, SIG_IGN);
|
||||||
|
|
||||||
/* Test initial path */
|
/* Test initial path */
|
||||||
|
|
3
nnn.h
3
nnn.h
|
@ -35,6 +35,7 @@ enum action {
|
||||||
SEL_REDRAW,
|
SEL_REDRAW,
|
||||||
SEL_COPY,
|
SEL_COPY,
|
||||||
SEL_COPYMUL,
|
SEL_COPYMUL,
|
||||||
|
SEL_QUOTE,
|
||||||
SEL_OPEN,
|
SEL_OPEN,
|
||||||
SEL_NEW,
|
SEL_NEW,
|
||||||
SEL_RENAME,
|
SEL_RENAME,
|
||||||
|
@ -148,6 +149,8 @@ static struct key bindings[] = {
|
||||||
{ CONTROL('K'), SEL_COPY, "", "" },
|
{ CONTROL('K'), SEL_COPY, "", "" },
|
||||||
/* Toggle copy multiple file paths */
|
/* Toggle copy multiple file paths */
|
||||||
{ CONTROL('Y'), SEL_COPYMUL, "", "" },
|
{ CONTROL('Y'), SEL_COPYMUL, "", "" },
|
||||||
|
/* Toggle quote on while copy */
|
||||||
|
{ CONTROL('T'), SEL_QUOTE, "", "" },
|
||||||
/* Open in a custom application */
|
/* Open in a custom application */
|
||||||
{ CONTROL('O'), SEL_OPEN, "", "" },
|
{ CONTROL('O'), SEL_OPEN, "", "" },
|
||||||
/* Create a new file */
|
/* Create a new file */
|
||||||
|
|
Loading…
Add table
Reference in a new issue