ZSH improvments

This commit is contained in:
Roey Darwish Dror
2019-02-27 10:06:54 +02:00
parent 5e6ee87df7
commit 32a151227a

View File

@@ -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<PathBuf, ()> {
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(())