fix(zplug): search appropriate paths for zplug folder
Check ZPLUG_HOME environment variable in addition to ~/.zplug. Also consider ZDOTDIR when sourcing .zshrc.
This commit is contained in:
@@ -1,20 +1,44 @@
|
|||||||
use crate::error::Error;
|
use crate::error::{Error, ErrorKind::*};
|
||||||
use crate::executor::{CommandExt, RunType};
|
use crate::executor::{CommandExt, RunType};
|
||||||
use crate::terminal::print_separator;
|
use crate::terminal::print_separator;
|
||||||
use crate::utils::{require, which};
|
use crate::utils::{require, which};
|
||||||
use directories::BaseDirs;
|
use directories::BaseDirs;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::process::Command;
|
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<String, ()> {
|
||||||
|
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)> {
|
pub fn run_zplug(base_dirs: &BaseDirs, run_type: RunType) -> Option<(&'static str, bool)> {
|
||||||
if let Some(zsh) = which("zsh") {
|
if let Some(zsh) = which("zsh") {
|
||||||
if base_dirs.home_dir().join(".zplug").exists() {
|
if zplug_exists(base_dirs) {
|
||||||
print_separator("zplug");
|
print_separator("zplug");
|
||||||
|
|
||||||
let success = || -> Result<(), Error> {
|
let success = || -> Result<(), Error> {
|
||||||
|
let zshrc = get_zshrc(base_dirs).map_err(|_| Error::from(SkipStep))?;
|
||||||
|
let cmd = format!("source {} && zplug update", zshrc);
|
||||||
run_type
|
run_type
|
||||||
.execute(zsh)
|
.execute(zsh)
|
||||||
.args(&["-c", "source ~/.zshrc && zplug update"])
|
.args(&["-c", cmd.as_str()])
|
||||||
.check_run()?;
|
.check_run()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}()
|
}()
|
||||||
|
|||||||
Reference in New Issue
Block a user