Skip to content

terminal_view: Fix terminal opening in / when no project is open#46582

Merged
Veykril merged 2 commits intozed-industries:mainfrom
maxmalkin:fix/terminal-open-path
Jan 13, 2026
Merged

terminal_view: Fix terminal opening in / when no project is open#46582
Veykril merged 2 commits intozed-industries:mainfrom
maxmalkin:fix/terminal-open-path

Conversation

@maxmalkin
Copy link
Contributor

@maxmalkin maxmalkin commented Jan 11, 2026

Closes #46574

The default_working_directory() function in crates/terminal_view/src/terminal_view.rs:1585 returned None when no project directory was available. The code comment (now removed) incorrectly claimed "None implies ~ on whichever machine we end up on". However, when None is passed to alacritty_terminal, it uses the process CWD, not the home directory. On macOS when Zed is launched from a .app bundle, the CWD is /.

Added a fallback at the end of default_working_directory() that explicitly returns the home directory when no project directory is found: directory.or_else(dirs::home_dir)

This ensures:

  1. CurrentProjectDirectory with no project open → home directory
  2. FirstProjectDirectory with no project open → home directory
  3. AlwaysHome → home directory (explicitly, not relying on shell behavior)
  4. Always { directory } with invalid directory → home directory

Release Notes:

  • Fixed terminal opening in / instead of home directory when no project is open.

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Jan 11, 2026
Copy link
Member

@Veykril Veykril left a comment

Choose a reason for hiding this comment

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

Thanks!

@Veykril Veykril changed the title Fix terminal opening in / when no project is open terminal_view: Fix terminal opening in / when no project is open Jan 12, 2026
@Veykril Veykril enabled auto-merge (squash) January 12, 2026 06:43
@zed-industries-bot
Copy link
Contributor

zed-industries-bot commented Jan 12, 2026

Warnings
⚠️

This PR is missing release notes.

Please add a "Release Notes" section that describes the change:

Release Notes:

- Added/Fixed/Improved ...

If your change is not user-facing, you can use "N/A" for the entry:

Release Notes:

- N/A

Generated by 🚫 dangerJS against c112d7c

@Veykril
Copy link
Member

Veykril commented Jan 12, 2026

/cherry-pick preview

@Veykril Veykril disabled auto-merge January 12, 2026 06:43
@Veykril Veykril enabled auto-merge (squash) January 12, 2026 06:43
auto-merge was automatically disabled January 12, 2026 20:01

Head branch was pushed to by a user without write access

@maxmalkin maxmalkin requested a review from Veykril January 12, 2026 20:02
@Veykril Veykril enabled auto-merge (squash) January 13, 2026 06:56
@Veykril Veykril merged commit d76258d into zed-industries:main Jan 13, 2026
24 checks passed
github-actions bot pushed a commit that referenced this pull request Jan 13, 2026
)

Closes #46574

The `default_working_directory()` function in
`crates/terminal_view/src/terminal_view.rs:1585` returned `None` when no
project directory was available. The code comment (now removed)
incorrectly claimed "None implies `~` on whichever machine we end up
on". However, when `None` is passed to `alacritty_terminal`, it uses the
process CWD, not the home directory. On macOS when Zed is launched from
a .`app` bundle, the CWD is `/`.
    
Added a fallback at the end of` default_working_directory()` that
explicitly returns the home directory when no project directory is
found: `directory.or_else(dirs::home_dir)`

  This ensures:
  1. `CurrentProjectDirectory` with no project open → home directory
  2. `FirstProjectDirectory `with no project open → home directory
3. `AlwaysHome `→ home directory (explicitly, not relying on shell
behavior)
  4. Always `{ directory }` with invalid directory → home directory



Release Notes:
- Fixed terminal opening in `/` instead of home directory when no
project is open.
zed-zippy bot added a commit that referenced this pull request Jan 13, 2026
) (cherry-pick to preview) (#46682)

Cherry-pick of #46582 to preview

----
Closes #46574

The `default_working_directory()` function in
`crates/terminal_view/src/terminal_view.rs:1585` returned `None` when no
project directory was available. The code comment (now removed)
incorrectly claimed "None implies `~` on whichever machine we end up
on". However, when `None` is passed to `alacritty_terminal`, it uses the
process CWD, not the home directory. On macOS when Zed is launched from
a .`app` bundle, the CWD is `/`.
    
Added a fallback at the end of` default_working_directory()` that
explicitly returns the home directory when no project directory is
found: `directory.or_else(dirs::home_dir)`

  This ensures:
  1. `CurrentProjectDirectory` with no project open → home directory
  2. `FirstProjectDirectory `with no project open → home directory
3. `AlwaysHome `→ home directory (explicitly, not relying on shell
behavior)
  4. Always `{ directory }` with invalid directory → home directory



Release Notes:
- Fixed terminal opening in `/` instead of home directory when no
project is open.

Co-authored-by: Max Malkin <60683392+maxmalkin@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Terminal opens to / when no projects are open

3 participants