4.0 KiB
Product Spec: Support ~ expansion in /open-file slash command
Issue: warpdotdev/warp-external#408 Figma: none provided
Summary
The /open-file slash command should expand ~ to the user's home directory, matching the behavior of the Cmd-O open file dialog. Currently, typing /open-file ~/foo.txt incorrectly prepends the working directory, producing a path like /current/dir/~/foo.txt instead of /home/user/foo.txt.
Problem
When a user types /open-file ~/some/file.txt and presses Enter, the ~ is treated as a literal directory name. The slash command handler joins the raw argument with the current working directory, resulting in a broken path like /Users/me/project/~/some/file.txt. This always fails with "File not found" because no literal ~ directory exists.
The Cmd-O (open file palette) already handles ~ correctly by calling shellexpand::tilde() before resolving the path. Users who discover ~ works in Cmd-O reasonably expect it to work in /open-file as well.
Goals
~at the start of a path in/open-fileexpands to the user's home directory.- Behavior is consistent with the Cmd-O open file palette.
- Existing relative and absolute path handling is unaffected.
Non-goals
- Supporting
$HOMEor other environment variable expansion in/open-file(follow-up if needed). - Supporting
~otherusersyntax (non-standard and not supported in Cmd-O either). - Changing how autosuggestions/completions populate paths (that is a separate concern).
User experience
Current behavior (broken)
- User types
/open-file ~/Documents/notes.txtand presses Enter. - The handler joins
~literally with the working directory, producing e.g./Users/me/project/~/Documents/notes.txt. - A "File not found" error toast appears.
Expected behavior (after fix)
- User types
/open-file ~/Documents/notes.txtand presses Enter. ~is expanded to the user's home directory (e.g./Users/me).- The resulting absolute path
/Users/me/Documents/notes.txtis used directly (not joined with the working directory). - If the file exists, it opens in Warp's code editor.
- If the file does not exist, the "File not found" toast shows the expanded path (e.g.
File not found: /Users/me/Documents/notes.txt), not the literal~form.
Edge cases
~alone:/open-file ~should show the "only works for files, not directories" error (since~expands to the home directory, which is a directory).~/prefix:/open-file ~/foo.txtexpands correctly.- No tilde:
/open-file foo.txtcontinues to resolve relative to the current working directory (unchanged). - Absolute paths:
/open-file /etc/hostscontinues to work (unchanged —PathBuf::joinwith an absolute path already replaces the base). - Escaped tilde from autosuggestion: If the path comes from shell autosuggestion with escape characters (e.g.
\~), the unescape step happens first, then tilde expansion applies to the unescaped result. - Line/column suffix:
/open-file ~/foo.txt:10:5should expand~and preserve the line/column argument.
Success criteria
/open-file ~/path/to/file.txtopens the file at$HOME/path/to/file.txt./open-file ~/path/to/file.txt:10opens the file at line 10./open-file relative/path.txtstill resolves relative to the working directory./open-file /absolute/path.txtstill works as an absolute path.- The "File not found" error toast displays the expanded path, not the literal
~. /open-file ~shows the "only works for files, not directories" error.- Behavior matches the Cmd-O file palette for
~paths.
Validation
- Unit test: Add a test that verifies
/open-file ~/somefileexpands~to the home directory and resolves to the correct absolute path. - Manual test: Type
/open-file ~/.bashrc(or any file known to exist in the home directory) and confirm it opens correctly. - Regression test: Confirm
/open-file relative.txtand/open-file /absolute/path.txtcontinue to work.
Open questions
None.