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:
parent
693ffbc764
commit
a5d143758a
4 changed files with 29 additions and 9 deletions
|
|
@ -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()?;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue