diff options
author | Mattias Andrée <m@maandree.se> | 2025-02-08 17:17:30 +0100 |
---|---|---|
committer | Mattias Andrée <m@maandree.se> | 2025-02-08 17:17:30 +0100 |
commit | 6c84566aad08dcfd49482e07543487ece4e23261 (patch) | |
tree | 6d217bbba0ed4044f84aca4b85cc6b5f68929d73 /sshexec.c | |
parent | Add cd option (diff) | |
download | sshexec-6c84566aad08dcfd49482e07543487ece4e23261.tar.gz sshexec-6c84566aad08dcfd49482e07543487ece4e23261.tar.bz2 sshexec-6c84566aad08dcfd49482e07543487ece4e23261.tar.xz |
Add asis and nasis options
Signed-off-by: Mattias Andrée <m@maandree.se>
Diffstat (limited to 'sshexec.c')
-rw-r--r-- | sshexec.c | 42 |
1 files changed, 37 insertions, 5 deletions
@@ -19,7 +19,8 @@ static void usage(void) { exitf("usage: %s [{ %s }] [ssh-option] ... destination command [argument] ...\n", - argv0, "[ssh=command] [dir=directory] [cd=(strict|lax)] [[fd]{>,>>,>|,<>}[&]=file]"); + argv0, "[ssh=command] [dir=directory] [cd=(strict|lax)] [[fd]{>,>>,>|,<>}[&]=file] " + "[asis=asis-marker [nasis=asis-count]]"); } @@ -130,6 +131,8 @@ main(int argc_unused, char *argv[]) const char *dir = NULL; const char *ssh = NULL; const char *cd = NULL; + const char *asis = NULL; + const char *nasis_str = NULL; struct redirection *redirections = NULL; size_t nredirections = 0; char *destination; @@ -142,6 +145,8 @@ main(int argc_unused, char *argv[]) const char **args; size_t i; int strict_cd; + unsigned long long int nasis = ULLONG_MAX; + int next_asis; (void) argc_unused; @@ -160,7 +165,8 @@ main(int argc_unused, char *argv[]) for (; *argv && strcmp(*argv, "}"); argv++) { STORE_OPT(&ssh, "ssh") STORE_OPT(&dir, "dir") - STORE_OPT(&cd, "cd") + STORE_OPT(&asis, "asis") + STORE_OPT(&nasis_str, "nasis") p = *argv; while (isdigit(*p)) @@ -212,6 +218,16 @@ main(int argc_unused, char *argv[]) else usage(); + if (nasis_str) { + char *end; + if (!asis || !isdigit(*nasis_str)) + usage(); + errno = 0; + nasis = strtoull(nasis_str, &end, 10); + if ((!nasis && errno) || *end) + usage(); + } + opts = argv; nopts = 0; while (*argv) { @@ -275,11 +291,27 @@ dest_dir_checked: build_command_escape(dir); build_command_asis(strict_cd ? " && " : " ; "); } - build_command_asis("exec env --"); + if (asis) + build_command_asis("( env --"); + else + build_command_asis("exec env --"); + next_asis = 0; for (; *argv; argv++) { - build_command_asis(" "); - build_command_escape(*argv); + if (asis && nasis && !strcmp(*argv, asis)) { + nasis -= 1U; + next_asis = 1; + } else { + build_command_asis(" "); + if (next_asis) { + next_asis = 0; + build_command_asis(*argv); + } else { + build_command_escape(*argv); + } + } } + if (asis) + build_command_asis(" )"); for (i = 0; i < nredirections; i++) { build_command_asis(" "); build_command_asis(redirections[i].asis); |