mirror of
https://github.com/jarun/nnn.git
synced 2024-11-24 20:01:27 +00:00
Remove file path quoting
This commit is contained in:
parent
06ff738b4c
commit
338b3be707
19
README.md
19
README.md
|
@ -60,7 +60,6 @@ It runs on Linux, OS X, Raspberry Pi, Cygwin, Linux subsystem for Windows and Te
|
||||||
- [add bookmarks](#add-bookmarks)
|
- [add bookmarks](#add-bookmarks)
|
||||||
- [copy file paths](#copy-file-paths)
|
- [copy file paths](#copy-file-paths)
|
||||||
- [selection](#selection)
|
- [selection](#selection)
|
||||||
- [quote paths](#quote-paths)
|
|
||||||
- [to clipboard](#to-clipboard)
|
- [to clipboard](#to-clipboard)
|
||||||
- [cd on quit](#cd-on-quit)
|
- [cd on quit](#cd-on-quit)
|
||||||
- [(neo)vim plugin](#neovim-plugin)
|
- [(neo)vim plugin](#neovim-plugin)
|
||||||
|
@ -222,17 +221,16 @@ Press <kbd>?</kbd> in `nnn` to see the list anytime.
|
||||||
→, ↵, l, ^M Open file/enter dir . Toggle show hidden
|
→, ↵, l, ^M Open file/enter dir . Toggle show hidden
|
||||||
/ Filter Ins, ^I Toggle nav-as-you-type
|
/ Filter Ins, ^I Toggle nav-as-you-type
|
||||||
b Pin current dir ^W Go to pinned dir
|
b Pin current dir ^W Go to pinned dir
|
||||||
^B Next active context
|
d Toggle detail view ^B Next active context
|
||||||
`, ^/ Leader key LeaderN Switch to context N
|
`, ^/ Leader key LeaderN Go to context N
|
||||||
Esc Exit prompt ^L Redraw, clear prompt
|
Esc Exit prompt ^L Redraw, clear prompt
|
||||||
^G Quit and cd q Quit context
|
^G Quit and cd q Quit context
|
||||||
Q, ^Q Quit ? Help, config
|
Q, ^Q Quit ? Help, config
|
||||||
FILES
|
FILES
|
||||||
^O Open with... n Create new
|
^O Open with... n Create new
|
||||||
D File details d Toggle detail view
|
D File details ^R Rename entry
|
||||||
^R Rename entry r Open dir in vidir
|
⎵, ^K Copy entry path r Open dir in vidir
|
||||||
Y, ^Y Toggle selection y List selection
|
Y, ^Y Toggle selection y List selection
|
||||||
⎵, ^K Copy entry path ^T Toggle path quote
|
|
||||||
P Copy selection X Delete selection
|
P Copy selection X Delete selection
|
||||||
V Move selection ^X Delete entry
|
V Move selection ^X Delete entry
|
||||||
f Archive entry F List archive
|
f Archive entry F List archive
|
||||||
|
@ -409,15 +407,6 @@ so you can easily handle files together:
|
||||||
# fish
|
# fish
|
||||||
ls -ltr (ncp)
|
ls -ltr (ncp)
|
||||||
|
|
||||||
##### quote paths
|
|
||||||
|
|
||||||
To wrap each file path within single quotes while selecting:
|
|
||||||
|
|
||||||
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.
|
|
||||||
|
|
||||||
##### to clipboard
|
##### to clipboard
|
||||||
|
|
||||||
Along with default copy, `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.
|
Along with default copy, `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.
|
||||||
|
|
6
nnn.1
6
nnn.1
|
@ -105,8 +105,6 @@ Toggle selection mode
|
||||||
Copy entry absolute path
|
Copy entry absolute path
|
||||||
.It Ic y
|
.It Ic y
|
||||||
Show selection list
|
Show selection list
|
||||||
.It Ic ^T
|
|
||||||
Toggle path quote
|
|
||||||
.It Ic P
|
.It Ic P
|
||||||
Copy files from selection
|
Copy files from selection
|
||||||
.It Ic V
|
.It Ic V
|
||||||
|
@ -296,10 +294,6 @@ files.
|
||||||
If it's not set, by default file paths are copied to the tmp file \fBDIR/.nnncp\fR, where 'DIR' (by priority) is: \fI$HOME\fR or, \fI$TMPDIR\fR or, \fI/tmp\fR.
|
If it's not set, by default file paths are copied to the tmp file \fBDIR/.nnncp\fR, where 'DIR' (by priority) is: \fI$HOME\fR or, \fI$TMPDIR\fR or, \fI/tmp\fR.
|
||||||
.Ed
|
.Ed
|
||||||
.Pp
|
.Pp
|
||||||
\fBNNN_QUOTE_ON:\fR wrap copied paths within single quotes. Useful for pasting
|
|
||||||
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.
|
\fBNNN_SCRIPT:\fR path to a custom script to invoke with currently selected file name as argument 1.
|
||||||
.Bd -literal
|
.Bd -literal
|
||||||
export NNN_SCRIPT=/usr/local/bin/nscript
|
export NNN_SCRIPT=/usr/local/bin/nscript
|
||||||
|
|
59
src/nnn.c
59
src/nnn.c
|
@ -258,10 +258,9 @@ typedef struct {
|
||||||
uint showcolor : 1; /* Set to show dirs in blue */
|
uint showcolor : 1; /* Set to show dirs in blue */
|
||||||
uint dircolor : 1; /* Current status of dir color */
|
uint dircolor : 1; /* Current status of dir color */
|
||||||
uint metaviewer : 1; /* Index of metadata viewer in utils[] */
|
uint metaviewer : 1; /* Index of metadata viewer in utils[] */
|
||||||
uint quote : 1; /* Copy paths within quotes */
|
|
||||||
uint color : 3; /* Color code for directories */
|
uint color : 3; /* Color code for directories */
|
||||||
uint ctxactive : 1; /* Context active or not */
|
uint ctxactive : 1; /* Context active or not */
|
||||||
uint reserved : 10;
|
uint reserved : 11;
|
||||||
/* The following settings are global */
|
/* The following settings are global */
|
||||||
uint curctx : 2; /* Current context number */
|
uint curctx : 2; /* Current context number */
|
||||||
uint picker : 1; /* Write selection to user-specified file */
|
uint picker : 1; /* Write selection to user-specified file */
|
||||||
|
@ -282,7 +281,7 @@ typedef struct {
|
||||||
/* GLOBALS */
|
/* GLOBALS */
|
||||||
|
|
||||||
/* Configuration, contexts */
|
/* Configuration, contexts */
|
||||||
static settings cfg = {0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 4, 1, 0, 0, 0, 0, 0};
|
static settings cfg = {0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 4, 1, 0, 0, 0, 0, 0};
|
||||||
static context g_ctx[MAX_CTX] __attribute__ ((aligned));
|
static context g_ctx[MAX_CTX] __attribute__ ((aligned));
|
||||||
|
|
||||||
static struct entry *dents;
|
static struct entry *dents;
|
||||||
|
@ -684,23 +683,10 @@ static bool appendfpath(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;
|
||||||
}
|
}
|
||||||
|
@ -1979,17 +1965,16 @@ static int show_help(char *path)
|
||||||
"4→, ↵, l, ^M Open file/enter dir . Toggle show hidden\n"
|
"4→, ↵, l, ^M Open file/enter dir . Toggle show hidden\n"
|
||||||
"e/ Filter Ins, ^I Toggle nav-as-you-type\n"
|
"e/ Filter Ins, ^I Toggle nav-as-you-type\n"
|
||||||
"eb Pin current dir ^W Go to pinned dir\n"
|
"eb Pin current dir ^W Go to pinned dir\n"
|
||||||
"d^B Next active context\n"
|
"ed Toggle detail view ^B Next active context\n"
|
||||||
"a`, ^/ Leader key LeaderN Go to context N\n"
|
"a`, ^/ Leader key LeaderN Go to context N\n"
|
||||||
"cEsc Exit prompt ^L Redraw, clear prompt\n"
|
"cEsc Exit prompt ^L Redraw, clear prompt\n"
|
||||||
"d^G Quit and cd q Quit context\n"
|
"d^G Quit and cd q Quit context\n"
|
||||||
"aQ, ^Q Quit ? Help, config\n"
|
"aQ, ^Q Quit ? Help, config\n"
|
||||||
"1FILES\n"
|
"1FILES\n"
|
||||||
"d^O Open with... n Create new\n"
|
"d^O Open with... n Create new\n"
|
||||||
"eD File details d Toggle detail view\n"
|
"eD File details ^R Rename entry\n"
|
||||||
"d^R Rename entry r Open dir in vidir\n"
|
"a⎵, ^K Copy entry path r Open dir in vidir\n"
|
||||||
"aY, ^Y Toggle selection y List selection\n"
|
"aY, ^Y Toggle selection y List selection\n"
|
||||||
"a⎵, ^K Copy entry path ^T Toggle path quote\n"
|
|
||||||
"eP Copy selection X Delete selection\n"
|
"eP Copy selection X Delete selection\n"
|
||||||
"eV Move selection ^X Delete entry\n"
|
"eV Move selection ^X Delete entry\n"
|
||||||
"ef Archive entry F List archive\n"
|
"ef Archive entry F List archive\n"
|
||||||
|
@ -2986,23 +2971,6 @@ nochange:
|
||||||
goto nochange;
|
goto nochange;
|
||||||
|
|
||||||
++ncp;
|
++ncp;
|
||||||
printmsg(newpath);
|
|
||||||
} else if (cfg.quote) {
|
|
||||||
g_buf[0] = '\'';
|
|
||||||
r = mkpath(path, dents[cur].name, g_buf + 1, PATH_MAX);
|
|
||||||
/* Keep the copy buf in sync */
|
|
||||||
copybufpos = 0;
|
|
||||||
appendfpath(g_buf + 1, r);
|
|
||||||
|
|
||||||
g_buf[r] = '\'';
|
|
||||||
g_buf[r + 1] = '\0';
|
|
||||||
|
|
||||||
writecp(g_buf, r + 1); /* Truncate NULL from end */
|
|
||||||
if (copier)
|
|
||||||
spawn(copier, g_buf, NULL, NULL, F_NOTRACE);
|
|
||||||
|
|
||||||
g_buf[r] = '\0';
|
|
||||||
printmsg(g_buf + 1);
|
|
||||||
} else {
|
} else {
|
||||||
r = mkpath(path, dents[cur].name, newpath, PATH_MAX);
|
r = mkpath(path, dents[cur].name, newpath, PATH_MAX);
|
||||||
/* Keep the copy buf in sync */
|
/* Keep the copy buf in sync */
|
||||||
|
@ -3012,9 +2980,8 @@ nochange:
|
||||||
writecp(newpath, r - 1); /* Truncate NULL from end */
|
writecp(newpath, r - 1); /* Truncate NULL from end */
|
||||||
if (copier)
|
if (copier)
|
||||||
spawn(copier, newpath, NULL, NULL, F_NOTRACE);
|
spawn(copier, newpath, NULL, NULL, F_NOTRACE);
|
||||||
|
|
||||||
printmsg(newpath);
|
|
||||||
}
|
}
|
||||||
|
printmsg(newpath);
|
||||||
goto nochange;
|
goto nochange;
|
||||||
case SEL_COPYMUL:
|
case SEL_COPYMUL:
|
||||||
if (!ndents)
|
if (!ndents)
|
||||||
|
@ -3113,14 +3080,6 @@ nochange:
|
||||||
if (cfg.filtermode)
|
if (cfg.filtermode)
|
||||||
presel = FILTER;
|
presel = FILTER;
|
||||||
goto begin;
|
goto begin;
|
||||||
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: // fallthrough
|
case SEL_OPEN: // fallthrough
|
||||||
case SEL_ARCHIVE:
|
case SEL_ARCHIVE:
|
||||||
if (!ndents)
|
if (!ndents)
|
||||||
|
@ -3569,10 +3528,6 @@ int main(int argc, char *argv[])
|
||||||
/* Get the clipboard copier, if set */
|
/* Get the clipboard copier, if set */
|
||||||
copier = getenv("NNN_COPIER");
|
copier = getenv("NNN_COPIER");
|
||||||
|
|
||||||
/* Enable quotes if opted */
|
|
||||||
if (getenv("NNN_QUOTE_ON"))
|
|
||||||
cfg.quote = 1;
|
|
||||||
|
|
||||||
if (getenv("HOME"))
|
if (getenv("HOME"))
|
||||||
g_tmpfplen = xstrlcpy(g_tmpfpath, getenv("HOME"), MAX_HOME_LEN);
|
g_tmpfplen = xstrlcpy(g_tmpfpath, getenv("HOME"), MAX_HOME_LEN);
|
||||||
else if (getenv("TMPDIR"))
|
else if (getenv("TMPDIR"))
|
||||||
|
|
|
@ -75,7 +75,6 @@ enum action {
|
||||||
SEL_MV,
|
SEL_MV,
|
||||||
SEL_RMMUL,
|
SEL_RMMUL,
|
||||||
SEL_RM,
|
SEL_RM,
|
||||||
SEL_QUOTE,
|
|
||||||
SEL_OPEN,
|
SEL_OPEN,
|
||||||
SEL_NEW,
|
SEL_NEW,
|
||||||
SEL_RENAME,
|
SEL_RENAME,
|
||||||
|
@ -210,8 +209,6 @@ static struct key bindings[] = {
|
||||||
{ 'X', SEL_RMMUL, "", "" },
|
{ 'X', SEL_RMMUL, "", "" },
|
||||||
/* Delete currently selected */
|
/* Delete currently selected */
|
||||||
{ CONTROL('X'), SEL_RM, "", "" },
|
{ CONTROL('X'), SEL_RM, "", "" },
|
||||||
/* 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…
Reference in a new issue