mirror of
https://github.com/jarun/nnn.git
synced 2025-01-23 17:26:42 +00:00
User control to disable prompt after run cmd as plugin
This commit is contained in:
parent
7b06480147
commit
fb2c548e86
|
@ -79,12 +79,20 @@ Now plugin `fzopen` can be run with the keybind <kbd>;o</kbd>, `mocplay` can be
|
||||||
|
|
||||||
## Running commands as plugin
|
## Running commands as plugin
|
||||||
|
|
||||||
To assign keys to arbitrary non-background cli commands (non-shell-interpreted) and invoke like plugins, add `_` (underscore) before the command. For example:
|
To assign keys to arbitrary non-background cli commands (non-shell-interpreted) and invoke like plugins, add `_` (underscore) before the command.
|
||||||
|
|
||||||
|
For example:
|
||||||
|
|
||||||
export NNN_PLUG='x:_chmod +x $nnn;g:_git log;s:_smplayer $nnn;o:fzopen'
|
export NNN_PLUG='x:_chmod +x $nnn;g:_git log;s:_smplayer $nnn;o:fzopen'
|
||||||
|
|
||||||
Now <kbd>;x</kbd> can be used to make a file executable, <kbd>;g</kbd> can be used to the git log of a git project directory, <kbd>;s</kbd> can be used to preview a partially downloaded media file.
|
Now <kbd>;x</kbd> can be used to make a file executable, <kbd>;g</kbd> can be used to the git log of a git project directory, <kbd>;s</kbd> can be used to preview a partially downloaded media file.
|
||||||
|
|
||||||
|
`nnn` waits for user confirmation when it executes a command as plugin (unline plugins which can add a `read` to wait). If you do not need to wait for user confirmation after the command has executed, add a `*` after the command. For example:
|
||||||
|
|
||||||
|
export NNN_PLUG='x:_chmod +x $nnn;g:_git log;s:_smplayer $nnn*;o:fzopen'
|
||||||
|
|
||||||
|
Now there will be no prompt after <kbd>;s</kbd>.
|
||||||
|
|
||||||
Notes:
|
Notes:
|
||||||
|
|
||||||
1. Use single quotes for `$NNN_PLUG` so `$nnn` is not interpreted
|
1. Use single quotes for `$NNN_PLUG` so `$nnn` is not interpreted
|
||||||
|
|
59
src/nnn.c
59
src/nnn.c
|
@ -3552,6 +3552,37 @@ static void show_help(const char *path)
|
||||||
unlink(g_tmpfpath);
|
unlink(g_tmpfpath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool run_cmd_as_plugin(const char *path, char *file, char *newpath, char *runfile)
|
||||||
|
{
|
||||||
|
uchar flags = F_CLI | F_CONFIRM;
|
||||||
|
size_t len;
|
||||||
|
|
||||||
|
DPRINTF_S(file);
|
||||||
|
|
||||||
|
/* Get rid of preceding _ */
|
||||||
|
++file;
|
||||||
|
|
||||||
|
if (!*file)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
len = strlen(file);
|
||||||
|
if (len > 1 && file[len - 1] == '*') {
|
||||||
|
flags &= ~F_CONFIRM; /* GUI case */
|
||||||
|
file[len - 1] = '\0'; /* Get rid of trailing nowait symbol */
|
||||||
|
--len;
|
||||||
|
}
|
||||||
|
|
||||||
|
xstrlcpy(newpath, file, PATH_MAX);
|
||||||
|
if (is_suffix(file, " $nnn")) {
|
||||||
|
/* Set `\0` to clear ' $nnn' suffix */
|
||||||
|
newpath[len - 5] = '\0';
|
||||||
|
} else
|
||||||
|
runfile = NULL;
|
||||||
|
|
||||||
|
spawn(newpath, runfile, NULL, path, flags);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
static bool plctrl_init(void)
|
static bool plctrl_init(void)
|
||||||
{
|
{
|
||||||
snprintf(g_buf, CMD_LEN_MAX, "nnn-pipe.%d", getpid());
|
snprintf(g_buf, CMD_LEN_MAX, "nnn-pipe.%d", getpid());
|
||||||
|
@ -3567,11 +3598,14 @@ static bool plctrl_init(void)
|
||||||
return _SUCCESS;
|
return _SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool run_selected_plugin(char **path, const char *file, char *newpath, char *runfile, char **lastname, char **lastdir)
|
static bool run_selected_plugin(char **path, char *file, char *newpath, char *runfile, char **lastname, char **lastdir)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
|
if (*file == '_')
|
||||||
|
return run_cmd_as_plugin(*path, file, newpath, runfile);
|
||||||
|
|
||||||
if (!g_plinit) {
|
if (!g_plinit) {
|
||||||
plctrl_init();
|
plctrl_init();
|
||||||
g_plinit = TRUE;
|
g_plinit = TRUE;
|
||||||
|
@ -5214,24 +5248,11 @@ nochange:
|
||||||
goto nochange;
|
goto nochange;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tmp[0] == '_' && tmp[1]) {
|
if (!run_selected_plugin(&path, tmp, newpath,
|
||||||
xstrlcpy(newpath, ++tmp, PATH_MAX);
|
(ndents ? dents[cur].name : NULL),
|
||||||
if (is_suffix(newpath, " $nnn")) {
|
&lastname, &lastdir)) {
|
||||||
tmp = (ndents ? dents[cur].name : NULL);
|
printwait(messages[MSG_FAILED], &presel);
|
||||||
/* Set `\0` to clear ' $nnn' suffix */
|
goto nochange;
|
||||||
newpath[strlen(newpath) - 5] = '\0';
|
|
||||||
} else
|
|
||||||
tmp = NULL;
|
|
||||||
|
|
||||||
spawn(newpath, tmp, NULL, path, F_CLI | F_CONFIRM);
|
|
||||||
} else {
|
|
||||||
if (!run_selected_plugin(&path, tmp, newpath,
|
|
||||||
(ndents ? dents[cur].name : NULL),
|
|
||||||
&lastname, &lastdir)) {
|
|
||||||
printwait(messages[MSG_FAILED],
|
|
||||||
&presel);
|
|
||||||
goto nochange;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ndents)
|
if (ndents)
|
||||||
|
|
Loading…
Reference in a new issue