diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2016-11-16 22:39:28 +0100 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2016-11-16 22:39:28 +0100 |
| commit | 4707fed2a21f4836b0eba28135040c3a456c9da9 (patch) | |
| tree | 7edbe2574c64edc690eeb917609e3d1a493e6158 /sam.c | |
| parent | 4a6df4bceaf76d4ed727ddf3510d69f65484324c (diff) | |
| download | vis-4707fed2a21f4836b0eba28135040c3a456c9da9.tar.gz vis-4707fed2a21f4836b0eba28135040c3a456c9da9.tar.xz | |
sam: use default shell command for <, >, | and ! when applicaple
If the shell command is omitted, the last shell command (of any type)
is substituted. The most recently used shell command is stored in a
new register currently named `!`.
Diffstat (limited to 'sam.c')
| -rw-r--r-- | sam.c | 12 |
1 files changed, 9 insertions, 3 deletions
@@ -492,9 +492,15 @@ static char *parse_text(const char **s) { return buf.data; } -static char *parse_shellcmd(const char **s) { +static char *parse_shellcmd(Vis *vis, const char **s) { skip_spaces(s); - return parse_until(s, "\n", NULL, false); + char *cmd = parse_until(s, "\n", NULL, false); + if (!cmd) { + const char *last_cmd = register_get(vis, &vis->registers[VIS_REG_SHELL], NULL); + return last_cmd ? strdup(last_cmd) : NULL; + } + register_put0(vis, &vis->registers[VIS_REG_SHELL], cmd); + return cmd; } static void parse_argv(const char **s, const char *argv[], size_t maxarg) { @@ -746,7 +752,7 @@ static Command *command_parse(Vis *vis, const char **s, int level, enum SamError } } - if (cmddef->flags & CMD_SHELL && !(cmd->argv[1] = parse_shellcmd(s))) { + if (cmddef->flags & CMD_SHELL && !(cmd->argv[1] = parse_shellcmd(vis, s))) { *err = SAM_ERR_SHELL; goto fail; } |
