summaryrefslogtreecommitdiff
path: root/tabbed/patches/tabbed-basenames-0.7.diff
blob: 5995ba9809c6531646aca13d945613628b77f2e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
From a682145f0daf599b6d2f6c1326f064ec67b30f73 Mon Sep 17 00:00:00 2001
From: Jacob Fong <jacobcfong@gmail.com>
Date: Mon, 5 Jun 2023 15:57:54 -0700
Subject: [PATCH] Added `-b` to display only basenames of tab titles.

---
 tabbed.1 |  3 +++
 tabbed.c | 24 ++++++++++++++++++++++--
 2 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/tabbed.1 b/tabbed.1
index 07bdbd7..4a9c110 100644
--- a/tabbed.1
+++ b/tabbed.1
@@ -106,6 +106,9 @@ defines the urgent background color.
 .BI \-U " urgfgbcol"
 defines the urgent foreground color.
 .TP
+.BI \-b
+print only basenames of tab titles.
+.TP
 .B \-v
 prints version information to stderr, then exits.
 .SH USAGE
diff --git a/tabbed.c b/tabbed.c
index eafe28a..03b0c8c 100644
--- a/tabbed.c
+++ b/tabbed.c
@@ -80,6 +80,7 @@ typedef struct {
 
 typedef struct {
 	char name[256];
+	char *basename;
 	Window win;
 	int tabx;
 	Bool urgent;
@@ -106,6 +107,7 @@ static void focusonce(const Arg *arg);
 static void focusurgent(const Arg *arg);
 static void fullscreen(const Arg *arg);
 static char *getatom(int a);
+static char *getbasename(const char *name);
 static int getclient(Window w);
 static XftColor getcolor(const char *colstr);
 static int getfirsttab(void);
@@ -156,7 +158,7 @@ static int bh, obh, wx, wy, ww, wh;
 static unsigned int numlockmask;
 static Bool running = True, nextfocus, doinitspawn = True,
             fillagain = False, closelastclient = False,
-            killclientsfirst = False;
+			killclientsfirst = False, basenametitles = False;
 static Display *dpy;
 static DC dc;
 static Atom wmatom[WMLast];
@@ -367,7 +369,10 @@ drawbar(void)
 		} else {
 			col = clients[c]->urgent ? dc.urg : dc.norm;
 		}
-		drawtext(clients[c]->name, col);
+		if (basenametitles)
+			drawtext(clients[c]->basename, col);
+		else
+			drawtext(clients[c]->name, col);
 		dc.x += dc.w;
 		clients[c]->tabx = dc.x;
 	}
@@ -557,6 +562,16 @@ getatom(int a)
 	return buf;
 }
 
+char *
+getbasename(const char *name)
+{
+	char *pos = strrchr(name, '/');
+	if (pos)
+		return pos+1;
+	else
+		return (char *)name;
+}
+
 int
 getclient(Window w)
 {
@@ -1217,6 +1232,8 @@ updatetitle(int c)
 	    sizeof(clients[c]->name)))
 		gettextprop(clients[c]->win, XA_WM_NAME, clients[c]->name,
 		            sizeof(clients[c]->name));
+	if (basenametitles)
+		clients[c]->basename = getbasename(clients[c]->name);
 	if (sel == c)
 		xsettitle(win, clients[c]->name);
 	drawbar();
@@ -1333,6 +1350,9 @@ main(int argc, char *argv[])
 	case 'u':
 		urgbgcolor = EARGF(usage());
 		break;
+	case 'b':
+		basenametitles = True;
+		break;
 	case 'v':
 		die("tabbed-"VERSION", © 2009-2016 tabbed engineers, "
 		    "see LICENSE for details.\n");
-- 
2.40.0