From 9d9330d6bc700b3252f0a2107412ce39f0b89dd6 Mon Sep 17 00:00:00 2001 From: Konstantin Fickel Date: Tue, 7 Apr 2026 13:49:12 +0200 Subject: [PATCH] fix: cross-platform compatibility for Windows support - Use directories::BaseDirs for config path fallback instead of hardcoded Unix path - Default to notepad on Windows instead of vi for editor commands - Skip +N line argument for notepad in todo edit (notepad doesn't support it) --- src/cli/commands/edit.rs | 8 +++++++- src/cli/commands/new.rs | 8 +++++++- src/cli/commands/todo.rs | 18 ++++++++++++------ src/config.rs | 4 +++- 4 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/cli/commands/edit.rs b/src/cli/commands/edit.rs index a8761f3..4c15017 100644 --- a/src/cli/commands/edit.rs +++ b/src/cli/commands/edit.rs @@ -67,7 +67,13 @@ pub fn run(number: i32) -> Result<(), StreamdError> { }; if let Some(file_path) = sorted_shards[selected_index].location.get("file") { - let editor = std::env::var("EDITOR").unwrap_or_else(|_| "vi".to_string()); + let editor = std::env::var("EDITOR").unwrap_or_else(|_| { + if cfg!(windows) { + "notepad".to_string() + } else { + "vi".to_string() + } + }); Command::new(&editor).arg(file_path).status()?; } diff --git a/src/cli/commands/new.rs b/src/cli/commands/new.rs index de7d351..5c3eecb 100644 --- a/src/cli/commands/new.rs +++ b/src/cli/commands/new.rs @@ -24,7 +24,13 @@ pub fn run() -> Result<(), StreamdError> { drop(file); // Open in editor - let editor = std::env::var("EDITOR").unwrap_or_else(|_| "vi".to_string()); + let editor = std::env::var("EDITOR").unwrap_or_else(|_| { + if cfg!(windows) { + "notepad".to_string() + } else { + "vi".to_string() + } + }); let status = Command::new(&editor).arg(&preliminary_path).status()?; if !status.success() { diff --git a/src/cli/commands/todo.rs b/src/cli/commands/todo.rs index 17bfba2..e54d1e2 100644 --- a/src/cli/commands/todo.rs +++ b/src/cli/commands/todo.rs @@ -92,13 +92,19 @@ pub fn run_edit(number: usize) -> Result<(), StreamdError> { .get("file") .ok_or(StreamdError::MissingFilePath)?; - let editor = std::env::var("EDITOR").unwrap_or_else(|_| "vi".to_string()); - let line_arg = format!("+{}", task.start_line); + let editor = std::env::var("EDITOR").unwrap_or_else(|_| { + if cfg!(windows) { + "notepad".to_string() + } else { + "vi".to_string() + } + }); - let status = Command::new(&editor) - .arg(&line_arg) - .arg(file_path) - .status()?; + let mut cmd = Command::new(&editor); + if !editor.to_lowercase().contains("notepad") { + cmd.arg(format!("+{}", task.start_line)); + } + let status = cmd.arg(file_path).status()?; if !status.success() { return Err(StreamdError::IoError(std::io::Error::other( diff --git a/src/config.rs b/src/config.rs index c828ba9..417e8f0 100644 --- a/src/config.rs +++ b/src/config.rs @@ -37,8 +37,10 @@ impl Settings { fn config_path() -> PathBuf { if let Some(proj_dirs) = ProjectDirs::from("", "", "streamd") { proj_dirs.config_dir().join("config.toml") + } else if let Some(base_dirs) = directories::BaseDirs::new() { + base_dirs.config_dir().join("streamd").join("config.toml") } else { - PathBuf::from("~/.config/streamd/config.toml") + PathBuf::from("streamd_config.toml") } } }