diff --git a/src/steps/os/unix.rs b/src/steps/os/unix.rs index a61c8ecc..895e8baa 100644 --- a/src/steps/os/unix.rs +++ b/src/steps/os/unix.rs @@ -1,20 +1,44 @@ -use crate::error::Error; +use crate::error::{Error, ErrorKind::*}; use crate::executor::{CommandExt, RunType}; use crate::terminal::print_separator; use crate::utils::{require, which}; use directories::BaseDirs; use std::path::Path; use std::process::Command; +use std::env; + +fn zplug_exists(base_dirs: &BaseDirs) -> bool { + let home_exists = match env::var("ZPLUG_HOME") { + Ok(ref zplug_home) => Path::new(zplug_home).exists(), + Err(_) => false, + }; + let dotdir_exists = base_dirs.home_dir().join(".zplug").exists(); + home_exists || dotdir_exists +} + +fn get_zshrc(base_dirs: &BaseDirs) -> Result { + let zshrc = match env::var("ZDOTDIR") { + Ok(ref zdotdir) => Ok(Path::new(zdotdir).join(".zshrc")), + Err(_) => Err(()), + }; + zshrc + .unwrap_or(base_dirs.home_dir().join(".zshrc")) + .to_str() + .map(|s| s.to_owned()) + .ok_or(()) +} pub fn run_zplug(base_dirs: &BaseDirs, run_type: RunType) -> Option<(&'static str, bool)> { if let Some(zsh) = which("zsh") { - if base_dirs.home_dir().join(".zplug").exists() { + if zplug_exists(base_dirs) { print_separator("zplug"); let success = || -> Result<(), Error> { + let zshrc = get_zshrc(base_dirs).map_err(|_| Error::from(SkipStep))?; + let cmd = format!("source {} && zplug update", zshrc); run_type .execute(zsh) - .args(&["-c", "source ~/.zshrc && zplug update"]) + .args(&["-c", cmd.as_str()]) .check_run()?; Ok(()) }()