commit 6a58c5e43db70d5574bed25a50f4f20a1659ee3a
parent 38f61e09119c06a07cafd15fa6b637f163af19c8
Author: Damian Myrda <damian@prime8.dev>
Date: Wed, 21 Oct 2026 08:39:00 +0000
fix(tui): complete paths relative to the shell's cwd
Diffstat:
2 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/internal/tui/shell.go b/internal/tui/shell.go
@@ -198,7 +198,11 @@ func (s *shellState) complete(root *vfs.Node) {
if i := strings.LastIndex(word, "/"); i >= 0 {
dirPart, base = word[:i+1], word[i+1:]
}
- dir := root.Lookup(vfs.Resolve(s.home, s.cwd, dirPart))
+ lookupDir := dirPart
+ if lookupDir == "" {
+ lookupDir = "." // vfs.Resolve("") means home, but completion is relative to cwd
+ }
+ dir := root.Lookup(vfs.Resolve(s.home, s.cwd, lookupDir))
if dir == nil || !dir.Dir {
return
}
diff --git a/internal/tui/shell_test.go b/internal/tui/shell_test.go
@@ -174,6 +174,21 @@ func TestShellCompletion(t *testing.T) {
}
}
+func TestShellCompletionRelativeToCwd(t *testing.T) {
+ m := testModel(t, 120, 60)
+ typeString(&m, "cd projects\n")
+ typeString(&m, "cat ja")
+ m.handleKeyMsg(tea.KeyMsg{Type: tea.KeyTab})
+ if m.shell.input != "cat janitor/" {
+ t.Fatalf("completion in cwd: %q", m.shell.input)
+ }
+ m.shell.input = "ls /ho"
+ m.handleKeyMsg(tea.KeyMsg{Type: tea.KeyTab})
+ if m.shell.input != "ls /home/" {
+ t.Fatalf("absolute completion: %q", m.shell.input)
+ }
+}
+
func TestShellUsesSessionUser(t *testing.T) {
m := testModel(t, 120, 80)
m.user = defaultUser("Dam/ian")