diff --git a/src/steps/os/unix.rs b/src/steps/os/unix.rs index 212c1839..6b0f4105 100644 --- a/src/steps/os/unix.rs +++ b/src/steps/os/unix.rs @@ -1,7 +1,7 @@ -use crate::error::{Error, ErrorKind::*}; +use crate::error::Error; use crate::executor::{CommandExt, RunType}; use crate::terminal::print_separator; -use crate::utils::{require, which}; +use crate::utils::{require, which, PathExt}; use directories::BaseDirs; use std::env; use std::path::{Path, PathBuf}; @@ -14,13 +14,10 @@ fn zplug_exists(base_dirs: &BaseDirs) -> bool { || base_dirs.home_dir().join("zplug").exists() } -fn get_zshrc(base_dirs: &BaseDirs) -> Result { +fn get_zshrc(base_dirs: &BaseDirs) -> PathBuf { env::var("ZDOTDIR") - .map(|ref zdotdir| Path::new(zdotdir).join(".zshrc")) - .unwrap_or_else(|_| base_dirs.home_dir().join(".zshrc")) - .to_str() .map(PathBuf::from) - .ok_or(()) + .unwrap_or_else(|_| base_dirs.home_dir().join(".zshrc")) } pub fn run_zplug(base_dirs: &BaseDirs, run_type: RunType) -> Option<(&'static str, bool)> { @@ -29,7 +26,7 @@ pub fn run_zplug(base_dirs: &BaseDirs, run_type: RunType) -> Option<(&'static st print_separator("zplug"); let success = || -> Result<(), Error> { - let zshrc = get_zshrc(base_dirs).map_err(|_| Error::from(SkipStep))?; + let zshrc = get_zshrc(base_dirs).require()?; let cmd = format!("source {} && zplug update", zshrc.display()); run_type.execute(zsh).args(&["-c", cmd.as_str()]).check_run()?; Ok(())