Unified · Split
| @@ -1,10 +1,11 @@ | ||
| 1 | 1 | #![cfg_attr(target_os = "linux", allow(dead_code))] |
| 2 | 2 | |
| 3 | 3 | use anyhow::{anyhow, Context, Result}; |
| 4 | −use clap::Parser; | |
| 4 | +use clap::{Error, ErrorKind, Parser}; | |
| 5 | 5 | use cli::{CliRequest, CliResponse}; |
| 6 | 6 | use serde::Deserialize; |
| 7 | 7 | use std::{ |
| 8 | + env, | |
| 8 | 9 | ffi::OsStr, |
| 9 | 10 | fs::{self, OpenOptions}, |
| 10 | 11 | io, |
| @@ -62,15 +63,15 @@ fn main() -> Result<()> { · 51 unmodified lines | ||
| 62 | 63 | return Ok(()); |
| 63 | 64 | } |
| 64 | 65 | |
| 65 | − for path in args | |
| 66 | − .paths_with_position | |
| 67 | − .iter() | |
| 68 | − .map(|path_with_position| &path_with_position.path_like) | |
| 69 | − { | |
| 70 | − if !path.exists() { | |
| 71 | − touch(path.as_path())?; | |
| 72 | − } | |
| 73 | − } | |
| 66 | + // for path in args | |
| 67 | + // .paths_with_position | |
| 68 | + // .iter() | |
| 69 | + // .map(|path_with_position| &path_with_position.path_like) | |
| 70 | + // { | |
| 71 | + // if !path.exists() { | |
| 72 | + // touch(path.as_path())?; | |
| 73 | + // } | |
| 74 | + // } | |
| 74 | 75 | |
| 75 | 76 | let (tx, rx) = bundle.launch()?; |
| 76 | 77 | let open_new_workspace = if args.new { |
| @@ -81,21 +82,35 @@ fn main() -> Result<()> { · 4 unmodified lines | ||
| 81 | 82 | None |
| 82 | 83 | }; |
| 83 | 84 | |
| 84 | − tx.send(CliRequest::Open { | |
| 85 | + tx.send(dbg!(CliRequest::Open { | |
| 85 | 86 | paths: args |
| 86 | 87 | .paths_with_position |
| 87 | 88 | .into_iter() |
| 88 | 89 | .map(|path_with_position| { |
| 89 | − let path_with_position = path_with_position.map_path_like(|path| { | |
| 90 | − fs::canonicalize(&path) | |
| 91 | − .with_context(|| format!("path {path:?} canonicalization")) | |
| 92 | − })?; | |
| 90 | + let path_with_position = | |
| 91 | + path_with_position.map_path_like(|path| match fs::canonicalize(&path) { | |
| 92 | + Ok(path) => Ok(path), | |
| 93 | + Err(e) => { | |
| 94 | + if let Some(mut parent) = path.parent() { | |
| 95 | + let curdir = env::current_dir()?; | |
| 96 | + if parent == Path::new("") { | |
| 97 | + parent = &curdir; | |
| 98 | + } | |
| 99 | + match fs::canonicalize(parent) { | |
| 100 | + Ok(parent) => Ok(parent.join(path.file_name().unwrap())), | |
| 101 | + Err(_) => Err(e), | |
| 102 | + } | |
| 103 | + } else { | |
| 104 | + Err(e) | |
| 105 | + } | |
| 106 | + } | |
| 107 | + })?; | |
| 93 | 108 | Ok(path_with_position.to_string(|path| path.display().to_string())) |
| 94 | 109 | }) |
| 95 | 110 | .collect::<Result<_>>()?, |
| 96 | 111 | wait: args.wait, |
| 97 | 112 | open_new_workspace, |
| 98 | − })?; | |
| 113 | + }))?; | |
| 99 | 114 | |
| 100 | 115 | while let Ok(response) = rx.recv() { |
| 101 | 116 | match response { |