Update oh-my-zsh plugins (fix #360) (#363)

This commit is contained in:
Roey Darwish Dror
2020-03-08 21:38:49 +02:00
committed by GitHub
parent ce7af763bb
commit 6692b74850
4 changed files with 65 additions and 22 deletions

View File

@@ -1,10 +1,15 @@
use crate::executor::RunType;
use crate::execution_context::ExecutionContext;
use crate::executor::{CommandExt, RunType};
use crate::git::Repositories;
use crate::terminal::print_separator;
use crate::utils::{require, PathExt};
use anyhow::Result;
use directories::BaseDirs;
use log::debug;
use std::env;
use std::fs;
use std::path::{Path, PathBuf};
use std::process::Command;
pub fn run_zr(base_dirs: &BaseDirs, run_type: RunType) -> Result<()> {
let zsh = require("zsh")?;
@@ -78,13 +83,35 @@ pub fn run_zinit(base_dirs: &BaseDirs, run_type: RunType) -> Result<()> {
run_type.execute(zsh).args(&["-i", "-c", cmd.as_str()]).check_run()
}
pub fn run_oh_my_zsh(base_dirs: &BaseDirs, run_type: RunType) -> Result<()> {
pub fn run_oh_my_zsh(ctx: &ExecutionContext) -> Result<()> {
require("zsh")?;
let oh_my_zsh = base_dirs.home_dir().join(".oh-my-zsh").require()?;
let oh_my_zsh = ctx.base_dirs().home_dir().join(".oh-my-zsh").require()?;
print_separator("oh-my-zsh");
run_type
let mut custom_dir = PathBuf::from(
Command::new("zsh")
.args(&["-i", "-c", "echo -n $ZSH_CUSTOM"])
.check_output()?,
);
custom_dir.push("plugins");
debug!("oh-my-zsh custom dir: {}", custom_dir.display());
let mut custom_plugins = Repositories::new(ctx.git());
for entry in fs::read_dir(custom_dir)? {
let entry = entry?;
custom_plugins.insert_if_repo(entry.path());
}
custom_plugins.remove(&oh_my_zsh.to_string_lossy());
if !custom_plugins.is_empty() {
println!("Pulling custom plugins");
ctx.git().multi_pull(&custom_plugins, ctx)?;
}
ctx.run_type()
.execute("sh")
.env("ZSH", &oh_my_zsh)
.arg(&oh_my_zsh.join("tools/upgrade.sh"))