[hackers] [lchat] use basename of cwd as window title by default || Jan Klemkow

From: <git_AT_suckless.org>
Date: Sun, 3 Sep 2017 01:39:33 +0200 (CEST)

commit f95191970fd59c52a8b09cff32bd8d2135cbfc6b
Author: Jan Klemkow <j.klemkow_AT_wemelug.de>
AuthorDate: Sun Sep 3 01:34:15 2017 +0200
Commit: Jan Klemkow <j.klemkow_AT_wemelug.de>
CommitDate: Sun Sep 3 01:34:15 2017 +0200

    use basename of cwd as window title by default

diff --git a/lchat.c b/lchat.c
index b691005..439d6b9 100644
--- a/lchat.c
+++ b/lchat.c
_AT_@ -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>
_AT_@ -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)
Received on Sun Sep 03 2017 - 01:39:33 CEST

This archive was generated by hypermail 2.3.0 : Sun Sep 03 2017 - 01:48:30 CEST