Pull zsh themes (fix #471) (#472)

This commit is contained in:
Roey Darwish Dror
2020-07-22 06:19:08 +03:00
committed by GitHub
parent b77bbf57dd
commit c01f8a7f48

View File

@@ -7,9 +7,9 @@ use anyhow::Result;
use directories::BaseDirs; use directories::BaseDirs;
use log::debug; use log::debug;
use std::env; use std::env;
use std::fs;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::process::Command; use std::process::Command;
use walkdir::WalkDir;
pub fn run_zr(base_dirs: &BaseDirs, run_type: RunType) -> Result<()> { pub fn run_zr(base_dirs: &BaseDirs, run_type: RunType) -> Result<()> {
let zsh = require("zsh")?; let zsh = require("zsh")?;
@@ -89,26 +89,36 @@ pub fn run_oh_my_zsh(ctx: &ExecutionContext) -> Result<()> {
print_separator("oh-my-zsh"); print_separator("oh-my-zsh");
let mut custom_dir = PathBuf::from( let custom_dir = env::var::<_>("ZSH_CUSTOM")
env::var::<_>("ZSH_CUSTOM") .or_else(|_| {
.or_else(|_| Command::new("zsh").args(&["-c", "echo -n $ZSH_CUSTOM"]).check_output())?, Command::new("zsh")
); .args(&["-c", "test $ZSH_CUSTOM && echo -n $ZSH_CUSTOM"])
custom_dir.push("plugins"); .check_output()
})
.map(PathBuf::from)
.unwrap_or_else(|e| {
let default_path = oh_my_zsh.join("custom");
debug!(
"Running zsh returned {}. Using default path: {}",
e,
default_path.display()
);
default_path
});
debug!("oh-my-zsh custom dir: {}", custom_dir.display()); debug!("oh-my-zsh custom dir: {}", custom_dir.display());
if let Ok(custom_plugins_dir) = fs::read_dir(custom_dir) { let mut custom_repos = Repositories::new(ctx.git());
let mut custom_plugins = Repositories::new(ctx.git());
for entry in custom_plugins_dir { for entry in WalkDir::new(custom_dir).max_depth(2) {
let entry = entry?; let entry = entry?;
custom_plugins.insert_if_repo(entry.path()); custom_repos.insert_if_repo(entry.path());
} }
custom_plugins.remove(&oh_my_zsh.to_string_lossy());
if !custom_plugins.is_empty() { custom_repos.remove(&oh_my_zsh.to_string_lossy());
println!("Pulling custom plugins"); if !custom_repos.is_empty() {
ctx.git().multi_pull(&custom_plugins, ctx)?; println!("Pulling custom plugins and themes");
} ctx.git().multi_pull(&custom_repos, ctx)?;
} }
ctx.run_type() ctx.run_type()