Fix config editing in Windows
This commit is contained in:
@@ -11,6 +11,7 @@ use std::process::Command;
|
|||||||
use std::{env, fs};
|
use std::{env, fs};
|
||||||
use structopt::StructOpt;
|
use structopt::StructOpt;
|
||||||
use strum::{EnumIter, EnumString, EnumVariantNames, IntoEnumIterator, VariantNames};
|
use strum::{EnumIter, EnumString, EnumVariantNames, IntoEnumIterator, VariantNames};
|
||||||
|
use which_crate::which;
|
||||||
|
|
||||||
#[allow(unused_macros)]
|
#[allow(unused_macros)]
|
||||||
macro_rules! str_value {
|
macro_rules! str_value {
|
||||||
@@ -243,8 +244,11 @@ impl ConfigFile {
|
|||||||
let config_path = Self::ensure(base_dirs)?;
|
let config_path = Self::ensure(base_dirs)?;
|
||||||
let editor = editor();
|
let editor = editor();
|
||||||
|
|
||||||
debug!("Editing {} with {}", config_path.display(), editor);
|
let command = which(&editor[0])?;
|
||||||
Command::new(editor)
|
let args: Vec<&String> = editor.iter().skip(1).collect();
|
||||||
|
|
||||||
|
Command::new(command)
|
||||||
|
.args(args)
|
||||||
.arg(config_path)
|
.arg(config_path)
|
||||||
.spawn()
|
.spawn()
|
||||||
.and_then(|mut p| p.wait())?;
|
.and_then(|mut p| p.wait())?;
|
||||||
|
|||||||
@@ -92,8 +92,12 @@ pub fn sudo() -> Option<PathBuf> {
|
|||||||
which("sudo").or_else(|| which("pkexec"))
|
which("sudo").or_else(|| which("pkexec"))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn editor() -> String {
|
pub fn editor() -> Vec<String> {
|
||||||
env::var("EDITOR").unwrap_or_else(|_| String::from(if cfg!(windows) { "notepad" } else { "vi" }))
|
env::var("EDITOR")
|
||||||
|
.unwrap_or_else(|_| String::from(if cfg!(windows) { "notepad" } else { "vi" }))
|
||||||
|
.split_whitespace()
|
||||||
|
.map(|s| s.to_owned())
|
||||||
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn require<T: AsRef<OsStr> + Debug>(binary_name: T) -> Result<PathBuf> {
|
pub fn require<T: AsRef<OsStr> + Debug>(binary_name: T) -> Result<PathBuf> {
|
||||||
|
|||||||
Reference in New Issue
Block a user