mirror of
https://github.com/jarun/nnn.git
synced 2024-11-24 20:01:27 +00:00
Group similar options in browse()
This commit is contained in:
parent
1a29b4ef36
commit
d029918282
94
src/nnn.c
94
src/nnn.c
|
@ -2017,13 +2017,13 @@ static bool handle_archive(char *fpath, char *arg, char *dir)
|
||||||
* the binary size by around a hundred bytes. This would only
|
* the binary size by around a hundred bytes. This would only
|
||||||
* have increased as we keep adding new options.
|
* have increased as we keep adding new options.
|
||||||
*/
|
*/
|
||||||
static int show_help(char *path)
|
static bool show_help(char *path)
|
||||||
{
|
{
|
||||||
if (g_tmpfpath[0])
|
if (g_tmpfpath[0])
|
||||||
xstrlcpy(g_tmpfpath + g_tmpfplen - 1, "/.nnnXXXXXX", HOME_LEN_MAX - g_tmpfplen);
|
xstrlcpy(g_tmpfpath + g_tmpfplen - 1, "/.nnnXXXXXX", HOME_LEN_MAX - g_tmpfplen);
|
||||||
else {
|
else {
|
||||||
printmsg(messages[STR_NOHOME_ID]);
|
printmsg(messages[STR_NOHOME_ID]);
|
||||||
return -1;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
int i = 0, fd = mkstemp(g_tmpfpath);
|
int i = 0, fd = mkstemp(g_tmpfpath);
|
||||||
|
@ -2062,7 +2062,7 @@ static int show_help(char *path)
|
||||||
"eR Run custom script L Lock terminal\n"};
|
"eR Run custom script L Lock terminal\n"};
|
||||||
|
|
||||||
if (fd == -1)
|
if (fd == -1)
|
||||||
return -1;
|
return FALSE;
|
||||||
|
|
||||||
start = end = helpstr;
|
start = end = helpstr;
|
||||||
while (*end) {
|
while (*end) {
|
||||||
|
@ -2134,7 +2134,7 @@ static int show_help(char *path)
|
||||||
get_output(NULL, 0, "cat", g_tmpfpath, NULL, TRUE);
|
get_output(NULL, 0, "cat", g_tmpfpath, NULL, TRUE);
|
||||||
unlink(g_tmpfpath);
|
unlink(g_tmpfpath);
|
||||||
refresh();
|
refresh();
|
||||||
return 0;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sum_bsizes(const char *fpath, const struct stat *sb,
|
static int sum_bsizes(const char *fpath, const struct stat *sb,
|
||||||
|
@ -2933,17 +2933,19 @@ nochange:
|
||||||
goto nochange;
|
goto nochange;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SEL_LIST: // fallthrough
|
|
||||||
case SEL_EXTRACT: // fallthrough
|
|
||||||
case SEL_MEDIA: // fallthrough
|
case SEL_MEDIA: // fallthrough
|
||||||
case SEL_FMEDIA: // fallthrough
|
case SEL_FMEDIA: // fallthrough
|
||||||
|
case SEL_ARCHIVELS: // fallthrough
|
||||||
|
case SEL_EXTRACT: // fallthrough
|
||||||
|
case SEL_RENAMEALL: // fallthrough
|
||||||
case SEL_RUNEDIT: // fallthrough
|
case SEL_RUNEDIT: // fallthrough
|
||||||
case SEL_RUNPAGE: // fallthrough
|
case SEL_RUNPAGE:
|
||||||
|
if (!ndents)
|
||||||
|
break; // fallthrough
|
||||||
|
case SEL_REDRAW: // fallthrough
|
||||||
|
case SEL_HELP: // fallthrough
|
||||||
case SEL_LOCK:
|
case SEL_LOCK:
|
||||||
{
|
{
|
||||||
if (!ndents)
|
|
||||||
break;
|
|
||||||
|
|
||||||
mkpath(path, dents[cur].name, newpath, PATH_MAX);
|
mkpath(path, dents[cur].name, newpath, PATH_MAX);
|
||||||
|
|
||||||
switch(sel) {
|
switch(sel) {
|
||||||
|
@ -2953,12 +2955,23 @@ nochange:
|
||||||
case SEL_FMEDIA:
|
case SEL_FMEDIA:
|
||||||
r = show_mediainfo(newpath, "-f");
|
r = show_mediainfo(newpath, "-f");
|
||||||
break;
|
break;
|
||||||
case SEL_LIST:
|
case SEL_ARCHIVELS:
|
||||||
r = handle_archive(newpath, "-l", path);
|
r = handle_archive(newpath, "-l", path);
|
||||||
break;
|
break;
|
||||||
case SEL_EXTRACT:
|
case SEL_EXTRACT:
|
||||||
r = handle_archive(newpath, "-x", path);
|
r = handle_archive(newpath, "-x", path);
|
||||||
break;
|
break;
|
||||||
|
case SEL_REDRAW:
|
||||||
|
if (ndents)
|
||||||
|
copycurname();
|
||||||
|
goto begin;
|
||||||
|
case SEL_RENAMEALL:
|
||||||
|
if ((r = getutil(utils[VIDIR])))
|
||||||
|
spawn(utils[VIDIR], ".", NULL, path, F_NORMAL);
|
||||||
|
break;
|
||||||
|
case SEL_HELP:
|
||||||
|
r = show_help(path);
|
||||||
|
break;
|
||||||
case SEL_RUNEDIT:
|
case SEL_RUNEDIT:
|
||||||
r = TRUE;
|
r = TRUE;
|
||||||
spawn(editor, editor_arg, dents[cur].name, path, F_NORMAL);
|
spawn(editor, editor_arg, dents[cur].name, path, F_NORMAL);
|
||||||
|
@ -2971,29 +2984,26 @@ nochange:
|
||||||
r = TRUE;
|
r = TRUE;
|
||||||
spawn(utils[LOCKER], NULL, NULL, NULL, F_NORMAL | F_SIGINT);
|
spawn(utils[LOCKER], NULL, NULL, NULL, F_NORMAL | F_SIGINT);
|
||||||
break;
|
break;
|
||||||
default:
|
default: /* unreachable */
|
||||||
r = TRUE;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (r == FALSE) {
|
|
||||||
printmsg("utility missing");
|
|
||||||
goto nochange;
|
goto nochange;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* In case of successful archive extract, reload contents */
|
if (!r) {
|
||||||
if (sel == SEL_EXTRACT) {
|
printmsg("required utility missing");
|
||||||
/* Continue in navigate-as-you-type mode, if enabled */
|
goto nochange;
|
||||||
if (cfg.filtermode)
|
|
||||||
presel = FILTER;
|
|
||||||
|
|
||||||
/* Save current */
|
|
||||||
copycurname();
|
|
||||||
|
|
||||||
/* Repopulate as directory content may have changed */
|
|
||||||
goto begin;
|
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
|
/* In case of successful operation, reload contents */
|
||||||
|
|
||||||
|
/* Continue in navigate-as-you-type mode, if enabled */
|
||||||
|
if (cfg.filtermode)
|
||||||
|
presel = FILTER;
|
||||||
|
|
||||||
|
/* Save current */
|
||||||
|
copycurname();
|
||||||
|
|
||||||
|
/* Repopulate as directory content may have changed */
|
||||||
|
goto begin;
|
||||||
}
|
}
|
||||||
case SEL_FSIZE:
|
case SEL_FSIZE:
|
||||||
cfg.sizeorder ^= 1;
|
cfg.sizeorder ^= 1;
|
||||||
|
@ -3043,11 +3053,6 @@ nochange:
|
||||||
if (ndents)
|
if (ndents)
|
||||||
copycurname();
|
copycurname();
|
||||||
goto begin;
|
goto begin;
|
||||||
case SEL_REDRAW:
|
|
||||||
/* Save current */
|
|
||||||
if (ndents)
|
|
||||||
copycurname();
|
|
||||||
goto begin;
|
|
||||||
case SEL_COPY:
|
case SEL_COPY:
|
||||||
if (!ndents)
|
if (!ndents)
|
||||||
goto nochange;
|
goto nochange;
|
||||||
|
@ -3374,25 +3379,6 @@ nochange:
|
||||||
close(fd);
|
close(fd);
|
||||||
xstrlcpy(lastname, tmp, NAME_MAX + 1);
|
xstrlcpy(lastname, tmp, NAME_MAX + 1);
|
||||||
goto begin;
|
goto begin;
|
||||||
case SEL_RENAMEALL:
|
|
||||||
if (!getutil(utils[VIDIR])) {
|
|
||||||
printmsg("utility missing");
|
|
||||||
goto nochange;
|
|
||||||
}
|
|
||||||
|
|
||||||
spawn(utils[VIDIR], ".", NULL, path, F_NORMAL);
|
|
||||||
|
|
||||||
/* Save current */
|
|
||||||
if (ndents)
|
|
||||||
copycurname();
|
|
||||||
goto begin;
|
|
||||||
case SEL_HELP:
|
|
||||||
show_help(path);
|
|
||||||
|
|
||||||
/* Continue in navigate-as-you-type mode, if enabled */
|
|
||||||
if (cfg.filtermode)
|
|
||||||
presel = FILTER;
|
|
||||||
break;
|
|
||||||
case SEL_RUN: // fallthrough
|
case SEL_RUN: // fallthrough
|
||||||
case SEL_RUNSCRIPT:
|
case SEL_RUNSCRIPT:
|
||||||
if (sel == SEL_RUNSCRIPT) {
|
if (sel == SEL_RUNSCRIPT) {
|
||||||
|
|
|
@ -61,7 +61,7 @@ enum action {
|
||||||
SEL_FMEDIA,
|
SEL_FMEDIA,
|
||||||
SEL_LAUNCH,
|
SEL_LAUNCH,
|
||||||
SEL_ARCHIVE,
|
SEL_ARCHIVE,
|
||||||
SEL_LIST,
|
SEL_ARCHIVELS,
|
||||||
SEL_EXTRACT,
|
SEL_EXTRACT,
|
||||||
SEL_FSIZE, /* file size */
|
SEL_FSIZE, /* file size */
|
||||||
SEL_ASIZE, /* apparent size */
|
SEL_ASIZE, /* apparent size */
|
||||||
|
@ -170,7 +170,7 @@ static struct key bindings[] = {
|
||||||
/* Create archive */
|
/* Create archive */
|
||||||
{ 'f', SEL_ARCHIVE },
|
{ 'f', SEL_ARCHIVE },
|
||||||
/* List archive */
|
/* List archive */
|
||||||
{ 'F', SEL_LIST },
|
{ 'F', SEL_ARCHIVELS },
|
||||||
/* Extract archive */
|
/* Extract archive */
|
||||||
{ CONTROL('F'), SEL_EXTRACT },
|
{ CONTROL('F'), SEL_EXTRACT },
|
||||||
/* Toggle sort by size */
|
/* Toggle sort by size */
|
||||||
|
|
Loading…
Reference in a new issue