prime8dev

prime8dev
git clone https://git.prime8.dev/prime8dev.git
Log | Files | Refs | README | LICENSE

commit 93159e24bf2d6c6f0bdb2478d1d2e2c6282bbe04
parent 76b9aff473c519da5cf13191c08b38cd16a0561a
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:
Minternal/tui/shell.go | 6+++++-
Minternal/tui/shell_test.go | 15+++++++++++++++
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")