Skip to content

fix(core): expand tilde (~) in /dir command path#366

Merged
chenhg5 merged 2 commits intochenhg5:mainfrom
z-xiaohua:fix/dir-tilde-expansion
Apr 2, 2026
Merged

fix(core): expand tilde (~) in /dir command path#366
chenhg5 merged 2 commits intochenhg5:mainfrom
z-xiaohua:fix/dir-tilde-expansion

Conversation

@z-xiaohua
Copy link
Copy Markdown
Contributor

Problem

/dir ~/workspace/project fails with "directory not found" because ~ is
treated as a literal character and gets joined to the current work dir,
resulting in an invalid path like /current/workdir/~/workspace/project.

Solution

Expand ~ and ~/ prefixes to the user's home directory via
os.UserHomeDir() + filepath.Join before path resolution in dirApply().

Cross-platform

os.UserHomeDir() and filepath.Join are Go stdlib — works on macOS,
Linux, and Windows.

Tests

Added TestCmdDir_ExpandsTilde covering:

  • ~ → home directory
  • ~/ → home directory
  • ~/Documents → subdirectory under home

shenghua-working and others added 2 commits March 26, 2026 23:15
Support ~ and ~/ prefix in /dir command so users can type paths like
~/workspace/project instead of requiring full absolute paths.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Owner

@chenhg5 chenhg5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Simple but useful fix.

Review notes:

  • ✅ CI passes
  • Expands ~ to home directory in /dir command
  • Uses stdlib os.UserHomeDir() — cross-platform
  • Good test coverage for ~, ~/, and ~/subdir

Approved for merge.

@chenhg5 chenhg5 merged commit 98ef87c into chenhg5:main Apr 2, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants