aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2021-06-07 00:46:50 +0200
committerJohn Ankarström <john@ankarstrom.se>2021-06-07 00:46:50 +0200
commit527f3da8646ae794ca4ba2b967c404cdcbb59d33 (patch)
treef0dbb64082f4672e2472e338231b1c93df5d315a
parent596a41139c08e172459d28fba0584f8ef6f576b5 (diff)
downloadnoice-527f3da8646ae794ca4ba2b967c404cdcbb59d33.tar.gz
Improve title formattingHEADmaster
-rw-r--r--noice.c1
-rw-r--r--safetitle.c20
-rw-r--r--safetitle.obin2452 -> 0 bytes
3 files changed, 16 insertions, 5 deletions
diff --git a/noice.c b/noice.c
index 68485db..15fd5e9 100644
--- a/noice.c
+++ b/noice.c
@@ -948,6 +948,7 @@ main(int argc, char *argv[])
/* Set locale before curses setup */
setlocale(LC_ALL, "");
initcurses();
+ safetitle(ipath);
browse(ipath, ifilter);
exitcurses();
exit(0);
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);
}
diff --git a/safetitle.o b/safetitle.o
deleted file mode 100644
index a3e7abf..0000000
--- a/safetitle.o
+++ /dev/null
Binary files differ