feat: Add --reuse/-r flag to CLI for replacing workspace in existing window - #1
Merged
Conversation
mateonoel2
marked this pull request as ready for review
September 14, 2025 07:50
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #ISSUE
it is was still in discussion
Release Notes:
--reuse(-r) CLI flag to replace the workspace in an existing window instead of opening a new oneThis PR adds a new
--reuse(-r) CLI flag that allows users to replace the workspace in an existing Zed window instead of opening a new one or adding files to the current workspace.What it does
The
--reuseflag finds an available local workspace window and replaces its workspace with the newly specified paths. This provides a third workspace opening mode alongside the existing--addand--newflags.Implementation Details
--reuse(-r) flag with proper mutual exclusion with--addand--newreplace_windowoption inworkspace::OpenOptionsBehavior
zed -r file.txt- Replaces the workspace in an available window withfile.txt-a/--addand-n/--newflagsFiles Changed
crates/cli/src/cli.rs- Addedreusefield toCliRequest::Opencrates/cli/src/main.rs- Added CLI argument definition and parsingcrates/zed/src/zed/open_listener.rs- Implemented reuse logic and added testscrates/zed/src/zed/windows_only_instance.rs- Updated for Windows compatibilityTesting
-aand-nflagsManual testing proof
In this first video we do a couple of tests:
1: What happens if we use the -r flag when there are no windows open?
- works as expected. It opens the files in a new window.
2: Does it work as expected if there is already a window open. Does it overrides the workspace?
- yes it does. When opening a different file it overrides the current window instead of creating a new one.
3: Does the -n flag still works as expected?
- yes, it creates the project in a new window
4: What about the -a flag?
- yes, on the last accessed page
5: we do the replace command. It overrides the first opened window, do we want this behavior?
- It is good enough that it overrides one of the opened windows with the new project. It still makes the user automatically go to the window with the specified files
6: we use the -r command again replacing the workspace with a new one.
- this indeed worked as expected
more_cli_testing.mp4
In here the we check how the --help flag now displays the new command. (Description was later updated)
comparing_cli_help.mp4