Add --add/--new to control CLI behaviour (#9202)
When neither is specified, if you open a directory you get a new workspace, otherwise files are added to your existing workspace. With --new files are always opened in a new workspace With --add directories are always added to an existing workspace Fixes #9076 Fixes #4861 Fixes #5370 Release Notes: - Added `-n/--new` and `-a/--add` to the zed CLI. When neither is specified, if you open a directory you get a new workspace, otherwise files are added to your existing workspace. With `--new` files are always opened in a new workspace, with `--add` directories are always added to an existing workspace. ([#9076](https://github.com/zed-industries/zed/issues/9096), [#4861](https://github.com/zed-industries/zed/issues/4861), [#5370](https://github.com/zed-industries/zed/issues/5370)).
This commit is contained in:
parent
89c67fb1ab
commit
05dfe96f0c
9 changed files with 369 additions and 103 deletions
|
@ -264,24 +264,14 @@ fn main() {
|
|||
cx.set_menus(app_menus());
|
||||
initialize_workspace(app_state.clone(), cx);
|
||||
|
||||
if stdout_is_a_pty() {
|
||||
// todo(linux): unblock this
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
upload_panics_and_crashes(http.clone(), cx);
|
||||
cx.activate(true);
|
||||
let urls = collect_url_args(cx);
|
||||
if !urls.is_empty() {
|
||||
listener.open_urls(urls)
|
||||
}
|
||||
} else {
|
||||
upload_panics_and_crashes(http.clone(), cx);
|
||||
// TODO Development mode that forces the CLI mode usually runs Zed binary as is instead
|
||||
// of an *app, hence gets no specific callbacks run. Emulate them here, if needed.
|
||||
if std::env::var(FORCE_CLI_MODE_ENV_VAR_NAME).ok().is_some()
|
||||
&& !listener.triggered.load(Ordering::Acquire)
|
||||
{
|
||||
listener.open_urls(collect_url_args(cx))
|
||||
}
|
||||
// todo(linux): unblock this
|
||||
upload_panics_and_crashes(http.clone(), cx);
|
||||
|
||||
cx.activate(true);
|
||||
|
||||
let urls = collect_url_args(cx);
|
||||
if !urls.is_empty() {
|
||||
listener.open_urls(urls)
|
||||
}
|
||||
|
||||
let mut triggered_authentication = false;
|
||||
|
@ -339,8 +329,13 @@ fn handle_open_request(
|
|||
if !request.open_paths.is_empty() {
|
||||
let app_state = app_state.clone();
|
||||
task = Some(cx.spawn(|mut cx| async move {
|
||||
let (_window, results) =
|
||||
open_paths_with_positions(&request.open_paths, app_state, &mut cx).await?;
|
||||
let (_window, results) = open_paths_with_positions(
|
||||
&request.open_paths,
|
||||
app_state,
|
||||
workspace::OpenOptions::default(),
|
||||
&mut cx,
|
||||
)
|
||||
.await?;
|
||||
for result in results.into_iter().flatten() {
|
||||
if let Err(err) = result {
|
||||
log::error!("Error opening path: {err}",);
|
||||
|
@ -441,9 +436,16 @@ async fn installation_id() -> Result<(String, bool)> {
|
|||
async fn restore_or_create_workspace(app_state: Arc<AppState>, cx: AsyncAppContext) {
|
||||
async_maybe!({
|
||||
if let Some(location) = workspace::last_opened_workspace_paths().await {
|
||||
cx.update(|cx| workspace::open_paths(location.paths().as_ref(), app_state, None, cx))?
|
||||
.await
|
||||
.log_err();
|
||||
cx.update(|cx| {
|
||||
workspace::open_paths(
|
||||
location.paths().as_ref(),
|
||||
app_state,
|
||||
workspace::OpenOptions::default(),
|
||||
cx,
|
||||
)
|
||||
})?
|
||||
.await
|
||||
.log_err();
|
||||
} else if matches!(KEY_VALUE_STORE.read_kvp(FIRST_OPEN), Ok(None)) {
|
||||
cx.update(|cx| show_welcome_view(app_state, cx)).log_err();
|
||||
} else {
|
||||
|
@ -901,7 +903,7 @@ fn collect_url_args(cx: &AppContext) -> Vec<String> {
|
|||
.filter_map(|arg| match std::fs::canonicalize(Path::new(&arg)) {
|
||||
Ok(path) => Some(format!("file://{}", path.to_string_lossy())),
|
||||
Err(error) => {
|
||||
if arg.starts_with("file://") {
|
||||
if arg.starts_with("file://") || arg.starts_with("zed-cli://") {
|
||||
Some(arg)
|
||||
} else if let Some(_) = parse_zed_link(&arg, cx) {
|
||||
Some(arg)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue