From: Scott Worley Date: Wed, 13 Sep 2023 22:23:13 +0000 (-0700) Subject: -C flag to specify directory X-Git-Tag: v1.0.0~1 X-Git-Url: http://git.scottworley.com/tl-append/commitdiff_plain/ff3c08a366b6a4b5178498d00a0e56612a6f1ec4?hp=7521e30b527409a49b129e344b20a87b7d5edf2b -C flag to specify directory -C chosen to match git's -C. --- diff --git a/tl-append.c b/tl-append.c index a3e9a4e..52d2602 100644 --- a/tl-append.c +++ b/tl-append.c @@ -27,7 +27,7 @@ typedef struct { } conf_t; void usage() { - die("usage: tl-append [-i] [--no-fnctl-lock] [--no-flock-lock]"); + die("usage: tl-append [-i] [-C dir] [--no-fnctl-lock] [--no-flock-lock]"); } conf_t parse_command_line(int argc, char *argv[]) { @@ -43,7 +43,13 @@ conf_t parse_command_line(int argc, char *argv[]) { conf.fcntl_lock = 0; else if (strcmp(argv[i], "--no-flock-lock") == 0) conf.flock_lock = 0; - else + else if (strcmp(argv[i], "-C") == 0) { + if (i + 1 >= argc) + die("-C requires a directory"); + if (chdir(argv[i + 1]) == -1) + die_err("Couldn't change directory"); + i++; + } else usage(); }