commit e9128d260575a52bf5673a05bd7cda764b9fb0bf
parent a9a7b27121824c3969f62df587fe0916d869cb83
Author: Jan Klemkow <j.klemkow@wemelug.de>
Date: Sat, 7 Nov 2015 05:04:52 +0100
add option to set the terminals window title
Diffstat:
2 files changed, 19 insertions(+), 3 deletions(-)
diff --git a/lchat.1 b/lchat.1
@@ -9,6 +9,7 @@
.Op Fl nh
.Op Fl H Ar lines
.Op Fl p Ar prompt
+.Op Fl t Ar title
.Op Fl i Ar in
.Op Fl o Ar out
.Op directory
@@ -35,6 +36,15 @@ of chat history.
Use
.Ar prompt
as prompt for the input line.
+.It Fl t Ar title
+Use
+.Ar title
+as title terminal window.
+In a
+.Xr tmux 1
+or
+.Xr screen 1
+environment its change the window name instead of the window title.
.It Fl i Ar in
Use path of
.Ar in
diff --git a/lchat.c b/lchat.c
@@ -57,8 +57,8 @@ line_output(struct slackline *sl, char *file)
static void
usage(void)
{
- fprintf(stderr, "lchar [-nh] [-H lines] [-p prompt] [-i in] [-o out] "
- "[directory]\n");
+ fprintf(stderr, "lchar [-nh] [-H lines] [-p prompt] [-t title] [-i in]"
+ " [-o out] [directory]\n");
exit(EXIT_FAILURE);
}
@@ -81,7 +81,7 @@ main(int argc, char *argv[])
char *out_file = NULL;
FILE *tail_fh;
- while ((ch = getopt(argc, argv, "H:i:no:p:h")) != -1) {
+ while ((ch = getopt(argc, argv, "H:i:no:p:t:h")) != -1) {
switch (ch) {
case 'H':
errno = 0;
@@ -105,6 +105,12 @@ main(int argc, char *argv[])
err(EXIT_FAILURE, "strdup");
prompt_len = strlen(prompt);
break;
+ case 't': /* set optarg to terminal's window title */
+ if (strcmp(getenv("TERM"), "screen") == 0)
+ printf("\033k%s\033\\", optarg);
+ else
+ printf("\033]0;%s\a", optarg);
+ break;
case 'h':
default:
usage();