commit f95191970fd59c52a8b09cff32bd8d2135cbfc6b
parent f6ab8c0931676e10e8af16b497231d25c55f2a1c
Author: Jan Klemkow <j.klemkow@wemelug.de>
Date: Sun, 3 Sep 2017 01:34:15 +0200
use basename of cwd as window title by default
Diffstat:
1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/lchat.c b/lchat.c
@@ -19,6 +19,8 @@
#include <err.h>
#include <errno.h>
#include <fcntl.h>
+#include <libgen.h>
+#include <limits.h>
#include <poll.h>
#include <signal.h>
#include <stdio.h>
@@ -255,13 +257,18 @@ main(int argc, char *argv[])
if (isatty(fd) == 0)
err(EXIT_FAILURE, "isatty");
- /* set optarg to terminal's window title */
- if (title != NULL) {
- if (strcmp(getenv("TERM"), "screen") == 0)
- printf("\033k%s\033\\", title);
- else
- printf("\033]0;%s\a", title);
+ /* set terminal's window title */
+ if (title == NULL) {
+ char path[PATH_MAX];
+ if (getcwd(path, sizeof path) == NULL)
+ err(EXIT_FAILURE, "getcwd");
+ if ((title = basename(path)) == NULL)
+ err(EXIT_FAILURE, "basename");
}
+ if (strcmp(getenv("TERM"), "screen") == 0)
+ printf("\033k%s\033\\", title);
+ else
+ printf("\033]0;%s\a", title);
/* preprate terminal reset on exit */
if (tcgetattr(fd, &origin_term) == -1)