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)
This commit is contained in:
Konstantin Fickel 2026-04-07 13:49:12 +02:00 committed by kfickel
parent 10f4ae282a
commit 4ded06748b
4 changed files with 29 additions and 9 deletions

View file

@ -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()?;
}

View file

@ -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() {

View file

@ -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(

View file

@ -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")
}
}
}