# terminal_view: Fix terminal opening in / when no project is open \(\#46582\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/d76258da9a48d8e92e803c4ccae1b91dda270e95)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: d76258da9a48d8e92e803c4ccae1b91dda270e95

Requested commit: d76258da9a48d8e92e803c4ccae1b91dda270e95

Commit: d76258da9a48d8e92e803c4ccae1b91dda270e95

Tree: 61b0dc78b239faa09da666c5e4b8f65c68c29106

Author: Max Malkin

Committer: GitHub

## Message

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

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.
```

## Parents

- [271bcf65ef8759591006e5127ca2da9d16a925fd](https://git.cafe/gitcafe/zed/commit/271bcf65ef8759591006e5127ca2da9d16a925fd?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/d76258da9a48d8e92e803c4ccae1b91dda270e95?format=markdown)
