aboutsummaryrefslogtreecommitdiffstats
path: root/sshexec.c
diff options
context:
space:
mode:
authorMattias Andrée <m@maandree.se>2025-02-08 16:16:19 +0100
committerMattias Andrée <m@maandree.se>2025-02-08 16:16:19 +0100
commitf880806d2ed3e0a60888eda59f348014f2b73f2f (patch)
treef1385b81b7e38e2cb52b84f2865028938003a8c2 /sshexec.c
parentUse `exec env --` instead of `exec --` (diff)
downloadsshexec-f880806d2ed3e0a60888eda59f348014f2b73f2f.tar.gz
sshexec-f880806d2ed3e0a60888eda59f348014f2b73f2f.tar.bz2
sshexec-f880806d2ed3e0a60888eda59f348014f2b73f2f.tar.xz
Add support for sshexec:// prefix and directory suffix in the destination argument
Signed-off-by: Mattias Andrée <m@maandree.se>
Diffstat (limited to 'sshexec.c')
-rw-r--r--sshexec.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/sshexec.c b/sshexec.c
index a6db757..67868ee 100644
--- a/sshexec.c
+++ b/sshexec.c
@@ -131,7 +131,8 @@ main(int argc_unused, char *argv[])
const char *ssh = NULL;
struct redirection *redirections = NULL;
size_t nredirections = 0;
- const char *destination;
+ char *destination;
+ char *dest_dir_delim;
char **opts, *p;
size_t nopts;
enum optclass class;
@@ -240,6 +241,25 @@ main(int argc_unused, char *argv[])
else if (strchr(*argv, '='))
exitf("%s: the command argument must contain an \'=\'\n", argv0);
+ if (!strncmp(destination, "sshexec://", sizeof("sshexec://") - 1U)) {
+ memmove(&destination[sizeof("ssh") - 1U],
+ &destination[sizeof("sshexec") - 1U],
+ strlen(&destination[sizeof("sshexec") - 1U]) + 1U);
+ goto using_ssh_prefix;
+ } else if (!strncmp(destination, "ssh://", sizeof("ssh://") - 1U)) {
+ using_ssh_prefix:
+ dest_dir_delim = strchr(&destination[sizeof("ssh://")], '/');
+ } else {
+ dest_dir_delim = strchr(destination, ':');
+ }
+ if (dest_dir_delim) {
+ if (dir)
+ exitf("%s: directory specified both in 'dir' option and in destination operand\n", argv0);
+ *dest_dir_delim++ = '\0';
+ dir = dest_dir_delim;
+ }
+dest_dir_checked:
+
if (dir) {
build_command_asis("cd -- ");
build_command_escape(dir);