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 349a639e90
commit 46766a9ec7
4 changed files with 29 additions and 9 deletions

View file

@ -44,7 +44,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

@ -72,13 +72,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(