From 86b3360429630d8ea78c440d8116e7248e40f9e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Mon, 7 Jun 2021 19:46:06 +0200 Subject: Rewrite /home/USER/ to ~/ --- tterm.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/tterm.c b/tterm.c index 626d414..0d70cb3 100644 --- a/tterm.c +++ b/tterm.c @@ -40,6 +40,24 @@ findwindow(unsigned int pid, Window w) return 0; } +char * +wd(char *path) +{ + char *username, *r; + + username = getenv("USER"); + r = strdup(path); + + if (strncmp(r, "/home/", 6) == 0) { + r += 5; + if (strncmp(r + 1, username, strlen(username)) == 0) + r += strlen(username); + r[0] = '~'; + } + + return r; +} + int main(int argc, char *argv[]) { @@ -94,7 +112,7 @@ main(int argc, char *argv[]) while ((len = getline(&line, &size, writefp)) != -1) { if (strncmp(line, "cwd", 3) == 0) { line += 3; line[len-4] = 0; /* chomp */ - cwd = strdup(line); + cwd = wd(line); XStoreName(display, w, cwd); XFlush(display); } else if (strncmp(line, "cmd", 3) == 0) { -- cgit v1.2.3