diff options
author | Karel Zak | 2018-05-14 12:51:50 +0200 |
---|---|---|
committer | Karel Zak | 2018-05-14 12:51:50 +0200 |
commit | 4d9b788d64c8f9de8cb28e541d53676f26386f3a (patch) | |
tree | e9788854cb6ff305b0a80657542fe790f763b299 /term-utils | |
parent | docs: add hint about script (diff) | |
download | kernel-qcow2-util-linux-4d9b788d64c8f9de8cb28e541d53676f26386f3a.tar.gz kernel-qcow2-util-linux-4d9b788d64c8f9de8cb28e541d53676f26386f3a.tar.xz kernel-qcow2-util-linux-4d9b788d64c8f9de8cb28e541d53676f26386f3a.zip |
script: add more info to script header
This patch introduces [...] to store extra information about terminal
to the typescript header. For example:
Script started on 2018-05-14 12:52:32+02:00 [TERM="xterm-256color" TTY="/dev/pts/3" COLS="190" LINES="53"]
or
Script started on 2018-05-14 12:54:01+02:00 [<not executed on terminal>]
if stdout is not terminal.
Addresses: https://github.com/karelzak/util-linux/issues/583
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'term-utils')
-rw-r--r-- | term-utils/script.c | 38 |
1 files changed, 33 insertions, 5 deletions
diff --git a/term-utils/script.c b/term-utils/script.c index 20c35d955..b7bec7e76 100644 --- a/term-utils/script.c +++ b/term-utils/script.c @@ -182,6 +182,36 @@ static void __attribute__((__noreturn__)) usage(void) exit(EXIT_SUCCESS); } +static void typescript_message_start(const struct script_control *ctl, time_t *tvec) +{ + char buf[FORMAT_TIMESTAMP_MAX]; + int cols = 0, lines = 0; + const char *tty = NULL, *term = NULL; + + if (!ctl->typescriptfp) + return; + + strtime_iso(tvec, ISO_TIMESTAMP, buf, sizeof(buf)); + + fprintf(ctl->typescriptfp, _("Script started on %s ["), buf); + + if (ctl->isterm) { + get_terminal_dimension(&cols, &lines); + get_terminal_name(&tty, NULL, NULL); + get_terminal_type(&term); + + if (term) + fprintf(ctl->typescriptfp, "TERM=\"%s\" ", term); + if (tty) + fprintf(ctl->typescriptfp, "TTY=\"%s\" ", tty); + + fprintf(ctl->typescriptfp, "COLS=\"%d\" LINES=\"%d\"", cols, lines); + } else + fprintf(ctl->typescriptfp, _("<not executed on terminal>")); + + fputs("]\n", ctl->typescriptfp); +} + static void die_if_link(const struct script_control *ctl) { struct stat s; @@ -496,11 +526,9 @@ static void do_io(struct script_control *ctl) } - if (ctl->typescriptfp) { - char buf[FORMAT_TIMESTAMP_MAX]; - strtime_iso(&tvec, ISO_TIMESTAMP, buf, sizeof(buf)); - fprintf(ctl->typescriptfp, _("Script started on %s\n"), buf); - } + if (ctl->typescriptfp) + typescript_message_start(ctl, &tvec); + gettime_monotonic(&ctl->oldtime); while (!ctl->die) { |