From ddbdb79256ee7129701aa22cc0eb30b3c417cbb0 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Fri, 12 Apr 2019 12:13:08 +0200 Subject: [PATCH] script: add option --log-out Let's make script(1) command line more explicit about typescript file. Signed-off-by: Karel Zak --- term-utils/script.1 | 6 +++++- term-utils/script.c | 17 ++++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/term-utils/script.1 b/term-utils/script.1 index 02ca31373a..3ae8909a66 100644 --- a/term-utils/script.1 +++ b/term-utils/script.1 @@ -47,7 +47,7 @@ assignment, as the typescript file can be printed out later with .PP If the argument .I file -is given, +or option \fB\-\-log\-out\fR \fIfile\fR is given, .B script saves the dialogue in this .IR file . @@ -87,6 +87,10 @@ being done using `cat foo'. Allow the default output destination, i.e. the typescript file, to be a hard or symbolic link. The command will follow a symbolic link. .TP +\fB\-O\fR, \fB\-\-log\-out\fR \fIfile\fR +Log output to the \fIfile\fR. The default is to log the file with name 'typescript' +if the option is not given. +.TP \fB\-o\fR, \fB\-\-output-limit\fR \fIsize\fR Limit the size of the typescript and timing files to .I size diff --git a/term-utils/script.c b/term-utils/script.c index 28e8de36eb..bef5557424 100644 --- a/term-utils/script.c +++ b/term-utils/script.c @@ -188,6 +188,7 @@ static void __attribute__((__noreturn__)) usage(void) fputs(_("Make a typescript of a terminal session.\n"), out); fputs(USAGE_OPTIONS, out); + fputs(_(" -O, --log-out log stdout to file (default)\n"), out); fputs(_(" -a, --append append the output\n"), out); fputs(_(" -c, --command run command rather than interactive shell\n"), out); fputs(_(" -e, --return return exit code of the child process\n"), out); @@ -895,6 +896,7 @@ int main(int argc, char **argv) {"return", no_argument, NULL, 'e'}, {"flush", no_argument, NULL, 'f'}, {"force", no_argument, NULL, FORCE_OPTION,}, + {"log-out", required_argument, NULL, 'O'}, {"output-limit", required_argument, NULL, 'o'}, {"quiet", no_argument, NULL, 'q'}, {"timing", optional_argument, NULL, 't'}, @@ -918,7 +920,7 @@ int main(int argc, char **argv) script_init_debug(); - while ((ch = getopt_long(argc, argv, "ac:efo:qt::Vh", longopts, NULL)) != -1) + while ((ch = getopt_long(argc, argv, "ac:efO:o:qt::Vh", longopts, NULL)) != -1) switch (ch) { case 'a': ctl.append = 1; @@ -935,6 +937,9 @@ int main(int argc, char **argv) case FORCE_OPTION: ctl.force = 1; break; + case 'O': + typescript = optarg; + break; case 'o': ctl.maxsz = strtosize_or_err(optarg, _("failed to parse output limit size")); break; @@ -961,10 +966,12 @@ int main(int argc, char **argv) argc -= optind; argv += optind; - if (argc > 0) - typescript = argv[0]; - else - die_if_link(&ctl, DEFAULT_TYPESCRIPT_FILENAME); + if (!typescript) { + if (argc > 0) + typescript = argv[0]; + else + die_if_link(&ctl, DEFAULT_TYPESCRIPT_FILENAME); + } /* associate stdout with typescript file */ log_associate(&ctl, &ctl.out, typescript, SCRIPT_FMT_RAW); -- 2.39.2