summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWormHeamer2026-01-02 17:21:34 -0500
committerWormHeamer2026-01-02 17:21:34 -0500
commit4849d0d9b6e2ff83e1c9f9512671de68f9bf177a (patch)
treec38ddc536188e782969b2783595cae7be81d4914
parent12214f20764340d4b04da7313fad35609ba86a7c (diff)
show current path as prompt, don't normalize "/" to ""
-rw-r--r--main.c30
1 files changed, 20 insertions, 10 deletions
diff --git a/main.c b/main.c
index ee083b7..2a3f666 100644
--- a/main.c
+++ b/main.c
@@ -1,4 +1,4 @@
-#define _POSIX_C_SOURCE 202511L
+#define _DEFAULT_SOURCE
#include <stdint.h>
#include <stddef.h>
@@ -516,9 +516,9 @@ static Str basename(Str s) {
}
static Str dirname(Str s) {
- while (s.n > 0 && s.s[s.n - 1] == '/') s.n--;
+ while (s.n > 1 && s.s[s.n - 1] == '/') s.n--;
while (s.n > 0 && s.s[s.n - 1] != '/') s.n--;
- while (s.n > 0 && s.s[s.n - 1] == '/') s.n--;
+ while (s.n > 1 && s.s[s.n - 1] == '/') s.n--;
return s;
}
@@ -1051,10 +1051,11 @@ static Str normalize_path(Str s) {
}
s = c.tail;
}
- Str path = { 0 };
+ Str path = S("/");
for (u32 i = 0; i < bits.n; i++) {
- str_catc(&path, '/', &e.scratch);
str_cat(&path, bits.v[i], &e.scratch);
+ if (i + 1 < bits.n)
+ str_catc(&path, '/', &e.scratch);
}
return path;
}
@@ -1338,15 +1339,22 @@ Str select_file_in(const char *path) {
again:
opt.n = 0;
- DA_APUSH(&opt, &e.scratch, S(".."));
+ if (strcmp(path, "/"))
+ DA_APUSH(&opt, &e.scratch, S(".."));
while ((de = readdir(d))) {
if (de->d_name[0] == '.') continue;
Str dn = str_from_cstr(de->d_name);
if (str_ends(dn, S(".o"))) continue;
Str n = str_dup(dn, &e.scratch);
+ if (de->d_type == DT_DIR)
+ str_catc(&n, '/', &e.scratch);
DA_APUSH(&opt, &e.scratch, n);
}
- int o = select_opt(opt.v, opt.n, S("File: "));
+
+ Str prompt = str_from_cstr(path);
+ str_cat(&prompt, S(": "), &e.scratch);
+
+ int o = select_opt(opt.v, opt.n, prompt);
if (o == -1) return (Str) { 0, 0 };
Str s = str_from_cstr(path);
@@ -1361,12 +1369,14 @@ again:
}
Str select_file(void) {
- const char *path = ".";
+ Str path = { 0 };
EditBuf *eb = &e.buf[e.bufi];
if (eb->type == ED_BUF_FILE || eb->type == ED_BUF_BIN_FILE) {
- path = str_to_cstr(dirname(eb->path), &e.scratch);
+ path = dirname(eb->path);
+ } else {
+ path = normalize_path(S("."));
}
- Str s = select_file_in(path);
+ Str s = select_file_in(str_to_cstr(path, &e.scratch));
return s;
}