summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWormHeamer2026-01-02 20:45:57 -0500
committerWormHeamer2026-01-02 20:45:57 -0500
commit2a0a6f2557f28aa14af0b79921c5d8e311730069 (patch)
tree260742c431af5c0c1e36459c5243af9a6dea3e77
parentffb3f1f3915484504e6136a4f028355e72947f8b (diff)
shorten homedir in some paths to ~
-rw-r--r--main.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/main.c b/main.c
index 76342c0..7942692 100644
--- a/main.c
+++ b/main.c
@@ -1043,6 +1043,15 @@ static Str normalize_path(Str s, Arena *a) {
return s;
}
+static Str shorten_path(Str s, Arena *a) {
+ if (str_starts(s, e.homedir)) {
+ Str sub = str_skip(s, e.homedir.n);
+ s = S("~");
+ str_cat(&s, sub, a);
+ }
+ return s;
+}
+
static void build_file(Str path, int debugp) {
(void)path;
shell_run(debugp ? "make DEBUG=1" : "make");
@@ -1338,7 +1347,7 @@ again:;
DA_APUSH(&opt, &e.scratch, n);
}
- Str prompt = str_from_cstr(path);
+ Str prompt = shorten_path(str_from_cstr(path), &e.scratch);
str_cat(&prompt, S(": "), &e.scratch);
int o = select_opt(opt.v, opt.n, prompt);
@@ -1386,8 +1395,9 @@ Str minimum_prefix(Str *s, u32 n) {
int select_buf(void) {
DYNARR(Str) opt = { 0 };
+ DA_AFIT(&opt, &e.scratch, e.bufn);
for (u32 i = 0; i < e.bufn; i++) {
- DA_APUSH(&opt, &e.scratch, e.buf[i].path);
+ DA_APUSH(&opt, &e.scratch, shorten_path(e.buf[i].path, &e.scratch));
}
ASSERT(opt.n == e.bufn);
Str prefix = minimum_prefix(opt.v, opt.n);
@@ -1750,7 +1760,7 @@ void edit_key(Editor *e, u32 c) {
int main(int argc, const char **argv) {
ed_init(&e);
- e.homedir = str_from_cstr(getenv("HOME"));
+ e.homedir = normalize_path(str_from_cstr(getenv("HOME")), &e.perm);
if (parse_edit_args(&e, argc, argv))
return 1;