aboutsummaryrefslogtreecommitdiffstats
path: root/src/app_draw.c
diff options
context:
space:
mode:
authoruser <user@clank>2026-09-10 15:42:47 +0200
committeruser <user@clank>2026-09-10 15:42:47 +0200
commite06abc0e1e3f4c3ba4630241fc4a77b5c745112e (patch)
tree3977a9df14468c1082d01c3c7c6ba0eba9b5e924 /src/app_draw.c
parentsidebar: what each tab's panes are saying, said under the tab (tab_bar_status) (diff)
downloadslosh-e06abc0e1e3f4c3ba4630241fc4a77b5c745112e.tar.gz
slosh-e06abc0e1e3f4c3ba4630241fc4a77b5c745112e.tar.xz
slosh-e06abc0e1e3f4c3ba4630241fc4a77b5c745112e.zip
tabs: an unnamed tab borrows the directory its focused pane is in
name, then purpose, then the basename of the focused pane's cwd, then the bare number. The kernel's answer (live_cwd, the same question save-workspace already asks), so a cd moves the label with you; home shows as ~. The focused pane rather than any consensus of the tab's panes: when they sit in different directories, the one you are typing into is what the tab is about, and a rule anyone can predict beats a cleverer one nobody can. Derived at draw time and never stored, so a real name wins the moment one exists, dumps and the tabs JSON stay unpolluted, and renaming starts from a genuinely empty name.
Diffstat (limited to 'src/app_draw.c')
-rw-r--r--src/app_draw.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/app_draw.c b/src/app_draw.c
index 5d358ad..b61d330 100644
--- a/src/app_draw.c
+++ b/src/app_draw.c
@@ -4,6 +4,7 @@
#include <ghostty/vt.h>
#include <ctype.h>
+#include <limits.h>
#include <stdarg.h>
#include <time.h>
#include <sys/stat.h>
@@ -1793,6 +1794,29 @@ static uint16_t draw_tab_cell(app_t *a, screen_t *s, size_t i, uint16_t x,
tab_t *t = &a->tabs[i];
char label[96];
const char *nm = t->name[0] ? t->name : (t->purpose[0] ? t->purpose : "");
+ /* An unnamed tab borrows the name of the directory its focused pane is in
+ * -- the kernel's answer, so a `cd` moves the label with you. The focused
+ * pane rather than any consensus of the tab's panes: when they disagree,
+ * the one you are typing into is what the tab is about, and a rule anyone
+ * can predict beats a cleverer one nobody can. Derived at draw time and
+ * never stored, so a real name or a purpose wins the moment one exists. */
+ char derived[80];
+ if (!nm[0]) {
+ node_t *f = t->focus ? t->focus : first_leaf_of(t->root);
+ char buf[PATH_MAX];
+ const char *cwd = f && f->pane ? live_cwd(f->pane, buf, sizeof buf) : NULL;
+ if (cwd && cwd[0]) {
+ const char *home = getenv("HOME");
+ if (home && home[0] && strcmp(cwd, home) == 0) {
+ nm = "~";
+ } else {
+ const char *base = strrchr(cwd, '/');
+ snprintf(derived, sizeof derived, "%s",
+ base && base[1] ? base + 1 : cwd);
+ nm = derived;
+ }
+ }
+ }
/* A pane that rang in a tab you are not looking at is invisible without
* this, and that is the case the whole indicator exists for. */
bool rang = CFG.bell_indicator && tab_has_bell(t);