mirror of
https://github.com/jarun/nnn.git
synced 2025-03-10 00:39:25 +00:00
Rename selection related tokens
This commit is contained in:
parent
3309736060
commit
1d5f1bf653
1 changed files with 51 additions and 51 deletions
102
src/nnn.c
102
src/nnn.c
|
@ -294,7 +294,7 @@ static char *shell;
|
||||||
static char *home;
|
static char *home;
|
||||||
static char *initpath;
|
static char *initpath;
|
||||||
static char *cfgdir;
|
static char *cfgdir;
|
||||||
static char *g_cppath;
|
static char *g_selpath;
|
||||||
static char *plugindir;
|
static char *plugindir;
|
||||||
static char *pnamebuf, *pselbuf;
|
static char *pnamebuf, *pselbuf;
|
||||||
static struct entry *dents;
|
static struct entry *dents;
|
||||||
|
@ -576,8 +576,8 @@ static void printerr(int linenum)
|
||||||
{
|
{
|
||||||
exitcurses();
|
exitcurses();
|
||||||
perror(xitoa(linenum));
|
perror(xitoa(linenum));
|
||||||
if (!cfg.picker && g_cppath)
|
if (!cfg.picker && g_selpath)
|
||||||
unlink(g_cppath);
|
unlink(g_selpath);
|
||||||
free(pselbuf);
|
free(pselbuf);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
@ -779,12 +779,12 @@ static int create_tmp_file()
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Writes buflen char(s) from buf to a file */
|
/* Writes buflen char(s) from buf to a file */
|
||||||
static void writecp(const char *buf, const size_t buflen)
|
static void writesel(const char *buf, const size_t buflen)
|
||||||
{
|
{
|
||||||
if (cfg.pickraw || !g_cppath)
|
if (cfg.pickraw || !g_selpath)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
FILE *fp = fopen(g_cppath, "w");
|
FILE *fp = fopen(g_selpath, "w");
|
||||||
if (fp) {
|
if (fp) {
|
||||||
if (fwrite(buf, 1, buflen, fp) != buflen)
|
if (fwrite(buf, 1, buflen, fp) != buflen)
|
||||||
printwarn(NULL);
|
printwarn(NULL);
|
||||||
|
@ -806,7 +806,7 @@ static void appendfpath(const char *path, const size_t len)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Write selected file paths to fd, linefeed separated */
|
/* Write selected file paths to fd, linefeed separated */
|
||||||
static size_t selectiontofd(int fd, uint *pcount)
|
static size_t seltofile(int fd, uint *pcount)
|
||||||
{
|
{
|
||||||
uint lastpos, count = 0;
|
uint lastpos, count = 0;
|
||||||
char *pbuf = pselbuf;
|
char *pbuf = pselbuf;
|
||||||
|
@ -845,7 +845,7 @@ static size_t selectiontofd(int fd, uint *pcount)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* List selection from selection buffer */
|
/* List selection from selection buffer */
|
||||||
static bool showcplist(void)
|
static bool listselbuf(void)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
size_t pos;
|
size_t pos;
|
||||||
|
@ -859,7 +859,7 @@ static bool showcplist(void)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
pos = selectiontofd(fd, NULL);
|
pos = seltofile(fd, NULL);
|
||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
if (pos && pos == selbufpos)
|
if (pos && pos == selbufpos)
|
||||||
|
@ -870,27 +870,27 @@ static bool showcplist(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* List selection from selection file (another instance) */
|
/* List selection from selection file (another instance) */
|
||||||
static bool showcpfile(void)
|
static bool listselfile(void)
|
||||||
{
|
{
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
|
|
||||||
if (stat(g_cppath, &sb) == -1)
|
if (stat(g_selpath, &sb) == -1)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
/* Nothing selected if file size is 0 */
|
/* Nothing selected if file size is 0 */
|
||||||
if (!sb.st_size)
|
if (!sb.st_size)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
snprintf(g_buf, CMD_LEN_MAX, "cat %s | tr \'\\0\' \'\\n\'", g_cppath);
|
snprintf(g_buf, CMD_LEN_MAX, "cat %s | tr \'\\0\' \'\\n\'", g_selpath);
|
||||||
spawn("sh", "-c", g_buf, NULL, F_NORMAL | F_CMD);
|
spawn("sh", "-c", g_buf, NULL, F_NORMAL | F_CMD);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool cpsafe(void)
|
static bool selsafe(void)
|
||||||
{
|
{
|
||||||
/* Fail if selection file path not generated */
|
/* Fail if selection file path not generated */
|
||||||
if (!g_cppath) {
|
if (!g_selpath) {
|
||||||
printmsg("selection file not found");
|
printmsg("selection file not found");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
@ -902,7 +902,7 @@ static bool cpsafe(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Fail if selection file path isn't accessible */
|
/* Fail if selection file path isn't accessible */
|
||||||
if (access(g_cppath, R_OK | W_OK) == -1) {
|
if (access(g_selpath, R_OK | W_OK) == -1) {
|
||||||
errno == ENOENT ? printmsg(messages[NONE_SELECTED]) : printwarn(NULL);
|
errno == ENOENT ? printmsg(messages[NONE_SELECTED]) : printwarn(NULL);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
@ -911,7 +911,7 @@ static bool cpsafe(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Reset selection indicators */
|
/* Reset selection indicators */
|
||||||
static void resetcpind(void)
|
static void resetselind(void)
|
||||||
{
|
{
|
||||||
int r = 0;
|
int r = 0;
|
||||||
|
|
||||||
|
@ -1158,9 +1158,9 @@ static void cpstr(char *buf)
|
||||||
{
|
{
|
||||||
snprintf(buf, CMD_LEN_MAX,
|
snprintf(buf, CMD_LEN_MAX,
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
"xargs -0 -a %s -%c {} %s {} .", g_cppath, REPLACE_STR, cp);
|
"xargs -0 -a %s -%c {} %s {} .", g_selpath, REPLACE_STR, cp);
|
||||||
#else
|
#else
|
||||||
"cat %s | xargs -0 -o -%c {} cp -iRp {} .", g_cppath, REPLACE_STR);
|
"cat %s | xargs -0 -o -%c {} cp -iRp {} .", g_selpath, REPLACE_STR);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1168,9 +1168,9 @@ static void mvstr(char *buf)
|
||||||
{
|
{
|
||||||
snprintf(buf, CMD_LEN_MAX,
|
snprintf(buf, CMD_LEN_MAX,
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
"xargs -0 -a %s -%c {} %s {} .", g_cppath, REPLACE_STR, mv);
|
"xargs -0 -a %s -%c {} %s {} .", g_selpath, REPLACE_STR, mv);
|
||||||
#else
|
#else
|
||||||
"cat %s | xargs -0 -o -%c {} mv -i {} .", g_cppath, REPLACE_STR);
|
"cat %s | xargs -0 -o -%c {} mv -i {} .", g_selpath, REPLACE_STR);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1179,16 +1179,16 @@ static void rmmulstr(char *buf)
|
||||||
if (cfg.trash) {
|
if (cfg.trash) {
|
||||||
snprintf(buf, CMD_LEN_MAX,
|
snprintf(buf, CMD_LEN_MAX,
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
"xargs -0 -a %s trash-put", g_cppath);
|
"xargs -0 -a %s trash-put", g_selpath);
|
||||||
#else
|
#else
|
||||||
"cat %s | xargs -0 trash-put", g_cppath);
|
"cat %s | xargs -0 trash-put", g_selpath);
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
snprintf(buf, CMD_LEN_MAX,
|
snprintf(buf, CMD_LEN_MAX,
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
"xargs -0 -a %s rm -%cr", g_cppath, confirm_force());
|
"xargs -0 -a %s rm -%cr", g_selpath, confirm_force());
|
||||||
#else
|
#else
|
||||||
"cat %s | xargs -0 -o rm -%cr", g_cppath, confirm_force());
|
"cat %s | xargs -0 -o rm -%cr", g_selpath, confirm_force());
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1241,8 +1241,8 @@ static bool batch_rename(const char *path)
|
||||||
for (i = 0; i < ndents; ++i)
|
for (i = 0; i < ndents; ++i)
|
||||||
appendfpath(dents[i].name, NAME_MAX);
|
appendfpath(dents[i].name, NAME_MAX);
|
||||||
|
|
||||||
selectiontofd(fd1, &count);
|
seltofile(fd1, &count);
|
||||||
selectiontofd(fd2, NULL);
|
seltofile(fd2, NULL);
|
||||||
close(fd2);
|
close(fd2);
|
||||||
|
|
||||||
if (dir) /* Don't retain dir entries in selection */
|
if (dir) /* Don't retain dir entries in selection */
|
||||||
|
@ -1303,10 +1303,10 @@ static void archive_selection(const char *cmd, const char *archive, const char *
|
||||||
|
|
||||||
snprintf(buf, CMD_LEN_MAX,
|
snprintf(buf, CMD_LEN_MAX,
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
"sed -ze 's|^%s/||' '%s' | xargs -0 %s %s", curpath, g_cppath, cmd, archive);
|
"sed -ze 's|^%s/||' '%s' | xargs -0 %s %s", curpath, g_selpath, cmd, archive);
|
||||||
#else
|
#else
|
||||||
"cat '%s' | tr '\\0' '\n' | sed -e 's|^%s/||' | tr '\n' '\\0' | xargs -0 %s %s",
|
"cat '%s' | tr '\\0' '\n' | sed -e 's|^%s/||' | tr '\n' '\\0' | xargs -0 %s %s",
|
||||||
g_cppath, curpath, cmd, archive);
|
g_selpath, curpath, cmd, archive);
|
||||||
#endif
|
#endif
|
||||||
spawn("sh", "-c", buf, curpath, F_NORMAL);
|
spawn("sh", "-c", buf, curpath, F_NORMAL);
|
||||||
free(buf);
|
free(buf);
|
||||||
|
@ -2899,8 +2899,8 @@ static bool show_help(const char *path)
|
||||||
dprintf(fd, "%s: %s\n", env_cfg[i], start);
|
dprintf(fd, "%s: %s\n", env_cfg[i], start);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (g_cppath)
|
if (g_selpath)
|
||||||
dprintf(fd, "SELECTION FILE: %s\n", g_cppath);
|
dprintf(fd, "SELECTION FILE: %s\n", g_selpath);
|
||||||
|
|
||||||
dprintf(fd, "\nv%s\n%s\n", VERSION, GENERAL_INFO);
|
dprintf(fd, "\nv%s\n%s\n", VERSION, GENERAL_INFO);
|
||||||
close(fd);
|
close(fd);
|
||||||
|
@ -3635,7 +3635,7 @@ nochange:
|
||||||
if (cfg.picker && sel == SEL_GOIN) {
|
if (cfg.picker && sel == SEL_GOIN) {
|
||||||
r = mkpath(path, dents[cur].name, newpath);
|
r = mkpath(path, dents[cur].name, newpath);
|
||||||
appendfpath(newpath, r);
|
appendfpath(newpath, r);
|
||||||
writecp(pselbuf, selbufpos - 1);
|
writesel(pselbuf, selbufpos - 1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4073,7 +4073,7 @@ nochange:
|
||||||
* the temporary selection file.
|
* the temporary selection file.
|
||||||
*/
|
*/
|
||||||
if (!nselected)
|
if (!nselected)
|
||||||
writecp(NULL, 0);
|
writesel(NULL, 0);
|
||||||
|
|
||||||
/* Do not select if already selected */
|
/* Do not select if already selected */
|
||||||
if (!(dents[cur].flags & FILE_SELECTED)) {
|
if (!(dents[cur].flags & FILE_SELECTED)) {
|
||||||
|
@ -4091,14 +4091,14 @@ nochange:
|
||||||
r = mkpath(path, dents[cur].name, newpath);
|
r = mkpath(path, dents[cur].name, newpath);
|
||||||
|
|
||||||
if (selbufpos) {
|
if (selbufpos) {
|
||||||
resetcpind();
|
resetselind();
|
||||||
|
|
||||||
/* Keep the selection buffer in sync */
|
/* Keep the selection buffer in sync */
|
||||||
selbufpos = 0;
|
selbufpos = 0;
|
||||||
}
|
}
|
||||||
appendfpath(newpath, r);
|
appendfpath(newpath, r);
|
||||||
|
|
||||||
writecp(newpath, r - 1); /* Truncate NULL from end */
|
writesel(newpath, r - 1); /* Truncate NULL from end */
|
||||||
spawn(copier, NULL, NULL, NULL, F_NOTRACE);
|
spawn(copier, NULL, NULL, NULL, F_NOTRACE);
|
||||||
|
|
||||||
nselected = 1;
|
nselected = 1;
|
||||||
|
@ -4109,8 +4109,8 @@ nochange:
|
||||||
cfg.selmode ^= 1;
|
cfg.selmode ^= 1;
|
||||||
if (cfg.selmode) {
|
if (cfg.selmode) {
|
||||||
if (selbufpos) {
|
if (selbufpos) {
|
||||||
resetcpind();
|
resetselind();
|
||||||
writecp(NULL, 0);
|
writesel(NULL, 0);
|
||||||
selbufpos = 0;
|
selbufpos = 0;
|
||||||
}
|
}
|
||||||
g_crc = crc8fast((uchar *)dents, ndents * sizeof(struct entry));
|
g_crc = crc8fast((uchar *)dents, ndents * sizeof(struct entry));
|
||||||
|
@ -4160,7 +4160,7 @@ nochange:
|
||||||
}
|
}
|
||||||
|
|
||||||
if (selbufpos) { /* File path(s) written to the buffer */
|
if (selbufpos) { /* File path(s) written to the buffer */
|
||||||
writecp(pselbuf, selbufpos - 1); /* Truncate NULL from end */
|
writesel(pselbuf, selbufpos - 1); /* Truncate NULL from end */
|
||||||
spawn(copier, NULL, NULL, NULL, F_NOTRACE);
|
spawn(copier, NULL, NULL, NULL, F_NOTRACE);
|
||||||
|
|
||||||
if (nselected) { /* Some files cherry picked */
|
if (nselected) { /* Some files cherry picked */
|
||||||
|
@ -4173,7 +4173,7 @@ nochange:
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
case SEL_SELLST:
|
case SEL_SELLST:
|
||||||
if (showcplist() || showcpfile()) {
|
if (listselbuf() || listselfile()) {
|
||||||
if (cfg.filtermode)
|
if (cfg.filtermode)
|
||||||
presel = FILTER;
|
presel = FILTER;
|
||||||
break;
|
break;
|
||||||
|
@ -4185,7 +4185,7 @@ nochange:
|
||||||
case SEL_MV:
|
case SEL_MV:
|
||||||
case SEL_RMMUL:
|
case SEL_RMMUL:
|
||||||
{
|
{
|
||||||
if (!cpsafe()) {
|
if (!selsafe()) {
|
||||||
presel = MSGWAIT;
|
presel = MSGWAIT;
|
||||||
goto nochange;
|
goto nochange;
|
||||||
}
|
}
|
||||||
|
@ -4242,7 +4242,7 @@ nochange:
|
||||||
case SEL_ARCHIVE:
|
case SEL_ARCHIVE:
|
||||||
r = get_input("archive selection (else current)? [y/Y confirms]");
|
r = get_input("archive selection (else current)? [y/Y confirms]");
|
||||||
if (r == 'y' || r == 'Y') {
|
if (r == 'y' || r == 'Y') {
|
||||||
if (!cpsafe()) {
|
if (!selsafe()) {
|
||||||
presel = MSGWAIT;
|
presel = MSGWAIT;
|
||||||
goto nochange;
|
goto nochange;
|
||||||
}
|
}
|
||||||
|
@ -4545,7 +4545,7 @@ nochange:
|
||||||
if (cfg.picker) {
|
if (cfg.picker) {
|
||||||
/* Picker mode: reset buffer or clear file */
|
/* Picker mode: reset buffer or clear file */
|
||||||
if (selbufpos)
|
if (selbufpos)
|
||||||
cfg.pickraw ? selbufpos = 0 : writecp(NULL, 0);
|
cfg.pickraw ? selbufpos = 0 : writesel(NULL, 0);
|
||||||
} else if (!write_lastdir(path)) {
|
} else if (!write_lastdir(path)) {
|
||||||
presel = MSGWAIT;
|
presel = MSGWAIT;
|
||||||
goto nochange;
|
goto nochange;
|
||||||
|
@ -4711,10 +4711,10 @@ static bool setup_config(void)
|
||||||
/* Set selection file path */
|
/* Set selection file path */
|
||||||
if (!cfg.picker) {
|
if (!cfg.picker) {
|
||||||
/* Length of "/.config/nnn/.selection" */
|
/* Length of "/.config/nnn/.selection" */
|
||||||
g_cppath = (char *)malloc(len + 3);
|
g_selpath = (char *)malloc(len + 3);
|
||||||
r = xstrlcpy(g_cppath, cfgdir, len + 3);
|
r = xstrlcpy(g_selpath, cfgdir, len + 3);
|
||||||
xstrlcpy(g_cppath + r - 1, "/.selection", 12);
|
xstrlcpy(g_selpath + r - 1, "/.selection", 12);
|
||||||
DPRINTF_S(g_cppath);
|
DPRINTF_S(g_selpath);
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
@ -4741,7 +4741,7 @@ static bool set_tmp_path()
|
||||||
|
|
||||||
static void cleanup(void)
|
static void cleanup(void)
|
||||||
{
|
{
|
||||||
free(g_cppath);
|
free(g_selpath);
|
||||||
free(plugindir);
|
free(plugindir);
|
||||||
free(cfgdir);
|
free(cfgdir);
|
||||||
free(initpath);
|
free(initpath);
|
||||||
|
@ -4806,8 +4806,8 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
g_cppath = realpath(optarg, NULL);
|
g_selpath = realpath(optarg, NULL);
|
||||||
unlink(g_cppath);
|
unlink(g_selpath);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'r':
|
case 'r':
|
||||||
|
@ -5039,12 +5039,12 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
if (cfg.pickraw) {
|
if (cfg.pickraw) {
|
||||||
if (selbufpos) {
|
if (selbufpos) {
|
||||||
opt = selectiontofd(1, NULL);
|
opt = seltofile(1, NULL);
|
||||||
if (opt != (int)(selbufpos))
|
if (opt != (int)(selbufpos))
|
||||||
xerror();
|
xerror();
|
||||||
}
|
}
|
||||||
} else if (!cfg.picker && g_cppath)
|
} else if (!cfg.picker && g_selpath)
|
||||||
unlink(g_cppath);
|
unlink(g_selpath);
|
||||||
|
|
||||||
/* Free the selection buffer */
|
/* Free the selection buffer */
|
||||||
free(pselbuf);
|
free(pselbuf);
|
||||||
|
|
Loading…
Add table
Reference in a new issue