diff options
author | John Ankarström <john@ankarstrom.se> | 2021-06-07 19:46:06 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2021-06-07 19:46:06 +0200 |
commit | 86b3360429630d8ea78c440d8116e7248e40f9e3 (patch) | |
tree | 698e01f8051b48cdc9dec6f1c4910be61115d677 | |
parent | ef1729c0f2f85ed66b9b5accbc0eb9a62af36ef2 (diff) | |
download | tterm-86b3360429630d8ea78c440d8116e7248e40f9e3.tar.gz |
Rewrite /home/USER/ to ~/
-rw-r--r-- | tterm.c | 20 |
1 files changed, 19 insertions, 1 deletions
@@ -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) { |