mirror of
https://github.com/jarun/nnn.git
synced 2025-02-17 23:04:55 +00:00
Changes for running scripts
This commit is contained in:
parent
a5755ec855
commit
71fbf80925
32
src/nnn.c
32
src/nnn.c
|
@ -1058,7 +1058,7 @@ static int entrycmp(const void *va, const void *vb)
|
||||||
* Also modifies the run and env pointers (used on SEL_{RUN,RUNARG}).
|
* Also modifies the run and env pointers (used on SEL_{RUN,RUNARG}).
|
||||||
* The next keyboard input can be simulated by presel.
|
* The next keyboard input can be simulated by presel.
|
||||||
*/
|
*/
|
||||||
static int nextsel(char **run, char **env, int *presel)
|
static int nextsel(int *presel)
|
||||||
{
|
{
|
||||||
static int c;
|
static int c;
|
||||||
static uint i;
|
static uint i;
|
||||||
|
@ -2537,7 +2537,7 @@ static void browse(char *ipath)
|
||||||
static char newpath[PATH_MAX] __attribute__ ((aligned));
|
static char newpath[PATH_MAX] __attribute__ ((aligned));
|
||||||
static char mark[PATH_MAX] __attribute__ ((aligned));
|
static char mark[PATH_MAX] __attribute__ ((aligned));
|
||||||
char *path, *lastdir, *lastname;
|
char *path, *lastdir, *lastname;
|
||||||
char *dir, *tmp, *run = NULL, *env = NULL;
|
char *dir, *tmp;
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
int r, fd, presel, ncp = 0, copystartid = 0, copyendid = 0;
|
int r, fd, presel, ncp = 0, copystartid = 0, copyendid = 0;
|
||||||
enum action sel;
|
enum action sel;
|
||||||
|
@ -2612,7 +2612,7 @@ nochange:
|
||||||
if (getppid() == 1)
|
if (getppid() == 1)
|
||||||
_exit(0);
|
_exit(0);
|
||||||
|
|
||||||
sel = nextsel(&run, &env, &presel);
|
sel = nextsel(&presel);
|
||||||
|
|
||||||
switch (sel) {
|
switch (sel) {
|
||||||
case SEL_BACK:
|
case SEL_BACK:
|
||||||
|
@ -3377,7 +3377,7 @@ nochange:
|
||||||
close(fd);
|
close(fd);
|
||||||
xstrlcpy(lastname, tmp, NAME_MAX + 1);
|
xstrlcpy(lastname, tmp, NAME_MAX + 1);
|
||||||
goto begin;
|
goto begin;
|
||||||
case SEL_RUN: // fallthrough
|
case SEL_SHELL: // fallthrough
|
||||||
case SEL_RUNSCRIPT:
|
case SEL_RUNSCRIPT:
|
||||||
if (sel == SEL_RUNSCRIPT) {
|
if (sel == SEL_RUNSCRIPT) {
|
||||||
tmp = getenv("NNN_SCRIPT");
|
tmp = getenv("NNN_SCRIPT");
|
||||||
|
@ -3388,31 +3388,29 @@ nochange:
|
||||||
tmp = xreadline(NULL, "script suffix: ");
|
tmp = xreadline(NULL, "script suffix: ");
|
||||||
if (tmp && tmp[0])
|
if (tmp && tmp[0])
|
||||||
xstrlcpy(newpath + _len - 1, tmp, PATH_MAX - _len);
|
xstrlcpy(newpath + _len - 1, tmp, PATH_MAX - _len);
|
||||||
|
|
||||||
tmp = newpath;
|
tmp = newpath;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *curfile = NULL;
|
dir = NULL; /* dir used as temp var */
|
||||||
|
|
||||||
if (ndents)
|
if (ndents)
|
||||||
curfile = dents[cur].name;
|
dir = dents[cur].name;
|
||||||
|
spawn(shell, tmp, dir, path, F_NORMAL | F_SIGINT);
|
||||||
spawn(shell, tmp, curfile, path, F_NORMAL | F_SIGINT);
|
} else {
|
||||||
} else
|
|
||||||
printmsg("set NNN_SCRIPT");
|
printmsg("set NNN_SCRIPT");
|
||||||
} else {
|
goto nochange;
|
||||||
|
}
|
||||||
|
} else
|
||||||
spawn(shell, shell_arg, NULL, path, F_NORMAL | F_MARKER);
|
spawn(shell, shell_arg, NULL, path, F_NORMAL | F_MARKER);
|
||||||
|
|
||||||
/* Continue in navigate-as-you-type mode, if enabled */
|
/* Continue in navigate-as-you-type mode, if enabled */
|
||||||
if (cfg.filtermode)
|
if (cfg.filtermode)
|
||||||
presel = FILTER;
|
presel = FILTER;
|
||||||
}
|
|
||||||
|
|
||||||
/* Save current */
|
/* Save current */
|
||||||
if (ndents)
|
if (ndents)
|
||||||
copycurname();
|
copycurname();
|
||||||
|
|
||||||
/* Repopulate as directory content may have changed */
|
/* Re-populate as directory content may have changed */
|
||||||
goto begin;
|
goto begin;
|
||||||
case SEL_QUITCD: // fallthrough
|
case SEL_QUITCD: // fallthrough
|
||||||
case SEL_QUIT:
|
case SEL_QUIT:
|
||||||
|
|
|
@ -80,7 +80,7 @@ enum action {
|
||||||
SEL_RENAME,
|
SEL_RENAME,
|
||||||
SEL_RENAMEALL,
|
SEL_RENAMEALL,
|
||||||
SEL_HELP,
|
SEL_HELP,
|
||||||
SEL_RUN,
|
SEL_SHELL,
|
||||||
SEL_RUNSCRIPT,
|
SEL_RUNSCRIPT,
|
||||||
SEL_RUNEDIT,
|
SEL_RUNEDIT,
|
||||||
SEL_RUNPAGE,
|
SEL_RUNPAGE,
|
||||||
|
@ -210,8 +210,8 @@ static struct key bindings[] = {
|
||||||
/* Show help */
|
/* Show help */
|
||||||
{ '?', SEL_HELP },
|
{ '?', SEL_HELP },
|
||||||
/* Run command */
|
/* Run command */
|
||||||
{ '!', SEL_RUN },
|
{ '!', SEL_SHELL },
|
||||||
{ CONTROL(']'), SEL_RUN },
|
{ CONTROL(']'), SEL_SHELL },
|
||||||
/* Run a custom script */
|
/* Run a custom script */
|
||||||
{ 'R', SEL_RUNSCRIPT },
|
{ 'R', SEL_RUNSCRIPT },
|
||||||
/* Run command with argument */
|
/* Run command with argument */
|
||||||
|
|
Loading…
Reference in a new issue