shithub: neindaw

Download patch

ref: 0adf8bbeee14c13e4fc7b710a356125fa2423e77
parent: 9068c05955073b4550f15380d0a2885d211f7e7e
author: Sigrid Haflínudóttir <ftrvxmtrx@gmail.com>
date: Wed Feb 5 07:22:38 EST 2020

cfg: better labeling when executed deeper than the top of an instance

--- a/cfg/cfg.c
+++ b/cfg/cfg.c
@@ -133,20 +133,25 @@
 {
 	UI *ui;
 	Dir *dirs;
-	char *s, *name;
+	char *s, *name, tmp[64];
 	long i, n;
 	int f;
 
+	/* FIXME perhaps a prefix common for all dirs should be removed too */
+	path = cleanname(path);
+
 	if ((f = open(path, OREAD)) < 0)
 		return nil;
 	ui = calloc(1, sizeof(*ui));
 	ui->path = strdup(path);
 	ui->ctl = -1;
-	if ((ui->label = strrchr(ui->path, '/')) == nil)
-		ui->label = ui->path;
-	else
-		ui->label++;
 
+	if ((s = strrchr(ui->path, '/')) == nil && fd2path(f, tmp, sizeof(tmp)) == 0) {
+		if ((s = strrchr(tmp, '/')) == nil)
+			s = path;
+	}
+	ui->label = strdup(s != nil ? s + 1 : ui->path);
+
 	while ((n = dirread(f, &dirs)) > 0) {
 		for (i = 0; i < n; i++) {
 			name = dirs[i].name;
@@ -277,10 +282,6 @@
 			s = ui->child[j]->path;
 			ch = ui->child[j]->child[0];
 
-			/* remove the annoying "./" if current dir was used */
-			/* FIXME perhaps a prefix common for all dirs should be removed too */
-			if (s[0] == '.' && s[1] == '/')
-				s += 2;
 			snprint(tmp, sizeof(tmp), "[%s] %s", s, ch->label);
 
 			if (mu_begin_window_ex(ch->win, tmp, winopt)) {