From 527f3da8646ae794ca4ba2b967c404cdcbb59d33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Mon, 7 Jun 2021 00:46:50 +0200 Subject: Improve title formatting --- safetitle.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'safetitle.c') diff --git a/safetitle.c b/safetitle.c index b9d8be0..cfecd24 100644 --- a/safetitle.c +++ b/safetitle.c @@ -86,6 +86,7 @@ check: void safetitle(char *title) { + char *t, *username; int ttyfd; if((ttyfd = open("/dev/tty", O_RDWR))==-1) @@ -95,10 +96,19 @@ safetitle(char *title) if(blacklisted(ttyfd)) return; - if(strncmp(title, "/home/", 6)==0) - title += 6; + username = getenv("USER"); + t = malloc((strlen(title)+1) * sizeof(char)); + if (t == NULL) + err(1, "malloc"); + strcpy(t, title); + + if (strncmp(t, "/home/", 6) == 0) { + t += 5; + if (strncmp(t + 1, username, strlen(username)) == 0) + t += strlen(username); + t[0] = '~'; + } - /* set title */ - if(screen) dprintf(ttyfd, "\033P\033]2;%s\007\033\\", title); - else dprintf(ttyfd, "\033]2;%s\007", title); + if(screen) dprintf(ttyfd, "\033P\033]2;%s\007\033\\", t); + else dprintf(ttyfd, "\033]2;%s\007", t); } -- cgit v1.2.3