2020-03-08 21:38:49 +02:00
|
|
|
use crate::execution_context::ExecutionContext;
|
|
|
|
|
use crate::executor::{CommandExt, RunType};
|
|
|
|
|
use crate::git::Repositories;
|
2019-10-01 20:50:44 +03:00
|
|
|
use crate::terminal::print_separator;
|
|
|
|
|
use crate::utils::{require, PathExt};
|
2019-12-11 23:05:38 +02:00
|
|
|
use anyhow::Result;
|
2019-10-01 20:50:44 +03:00
|
|
|
use directories::BaseDirs;
|
2020-03-08 21:38:49 +02:00
|
|
|
use log::debug;
|
2019-10-01 20:50:44 +03:00
|
|
|
use std::env;
|
2020-03-08 21:38:49 +02:00
|
|
|
use std::fs;
|
2019-10-01 20:50:44 +03:00
|
|
|
use std::path::{Path, PathBuf};
|
2020-03-08 21:38:49 +02:00
|
|
|
use std::process::Command;
|
2019-10-01 20:50:44 +03:00
|
|
|
|
2019-12-11 23:05:38 +02:00
|
|
|
pub fn run_zr(base_dirs: &BaseDirs, run_type: RunType) -> Result<()> {
|
2019-10-01 20:50:44 +03:00
|
|
|
let zsh = require("zsh")?;
|
|
|
|
|
|
|
|
|
|
env::var("ZR_HOME")
|
|
|
|
|
.map(PathBuf::from)
|
|
|
|
|
.unwrap_or_else(|_| base_dirs.home_dir().join(".zr"))
|
|
|
|
|
.require()?;
|
|
|
|
|
|
|
|
|
|
print_separator("zr");
|
|
|
|
|
|
|
|
|
|
let cmd = format!("source {} && zr update", zshrc(base_dirs).display());
|
2020-01-16 10:23:37 +02:00
|
|
|
run_type.execute(zsh).args(&["-l", "-c", cmd.as_str()]).check_run()
|
2019-10-01 20:50:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn zshrc(base_dirs: &BaseDirs) -> PathBuf {
|
|
|
|
|
env::var("ZDOTDIR")
|
|
|
|
|
.map(|p| Path::new(&p).join(".zshrc"))
|
|
|
|
|
.unwrap_or_else(|_| base_dirs.home_dir().join(".zshrc"))
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-11 06:57:30 +01:00
|
|
|
pub fn run_antibody(run_type: RunType) -> Result<()> {
|
|
|
|
|
require("zsh")?;
|
|
|
|
|
let antibody = require("antibody")?;
|
|
|
|
|
|
|
|
|
|
print_separator("antibody");
|
|
|
|
|
|
|
|
|
|
run_type.execute(antibody).arg("update").check_run()
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-11 23:05:38 +02:00
|
|
|
pub fn run_antigen(base_dirs: &BaseDirs, run_type: RunType) -> Result<()> {
|
2019-10-01 20:50:44 +03:00
|
|
|
let zsh = require("zsh")?;
|
|
|
|
|
let zshrc = zshrc(base_dirs).require()?;
|
|
|
|
|
env::var("ADOTDIR")
|
|
|
|
|
.map(PathBuf::from)
|
|
|
|
|
.unwrap_or_else(|_| base_dirs.home_dir().join("antigen.zsh"))
|
|
|
|
|
.require()?;
|
|
|
|
|
|
|
|
|
|
print_separator("antigen");
|
|
|
|
|
|
|
|
|
|
let cmd = format!("source {} && antigen selfupdate && antigen update", zshrc.display());
|
2020-01-16 10:23:37 +02:00
|
|
|
run_type.execute(zsh).args(&["-l", "-c", cmd.as_str()]).check_run()
|
2019-10-01 20:50:44 +03:00
|
|
|
}
|
|
|
|
|
|
2019-12-11 23:05:38 +02:00
|
|
|
pub fn run_zplug(base_dirs: &BaseDirs, run_type: RunType) -> Result<()> {
|
2019-10-01 20:50:44 +03:00
|
|
|
let zsh = require("zsh")?;
|
2020-03-06 10:57:30 +02:00
|
|
|
zshrc(base_dirs).require()?;
|
2019-10-01 20:50:44 +03:00
|
|
|
|
|
|
|
|
env::var("ZPLUG_HOME")
|
|
|
|
|
.map(PathBuf::from)
|
|
|
|
|
.unwrap_or_else(|_| base_dirs.home_dir().join("zplug"))
|
|
|
|
|
.require()?;
|
|
|
|
|
|
|
|
|
|
print_separator("zplug");
|
|
|
|
|
|
2020-03-06 10:57:30 +02:00
|
|
|
run_type.execute(zsh).args(&["-i", "-c", "zplug update"]).check_run()
|
2019-10-01 20:50:44 +03:00
|
|
|
}
|
|
|
|
|
|
2020-02-12 23:59:28 -06:00
|
|
|
pub fn run_zinit(base_dirs: &BaseDirs, run_type: RunType) -> Result<()> {
|
2019-12-01 06:40:23 +00:00
|
|
|
let zsh = require("zsh")?;
|
|
|
|
|
let zshrc = zshrc(base_dirs).require()?;
|
|
|
|
|
|
2020-02-20 17:29:11 +02:00
|
|
|
env::var("ZPFX")
|
2020-02-16 15:59:10 +02:00
|
|
|
.map(PathBuf::from)
|
|
|
|
|
.unwrap_or_else(|_| base_dirs.home_dir().join(".zinit"))
|
2020-02-20 17:29:11 +02:00
|
|
|
.require()?;
|
2020-02-17 21:10:17 +02:00
|
|
|
|
|
|
|
|
print_separator("zinit");
|
2020-02-15 08:11:45 -06:00
|
|
|
|
2020-02-20 17:29:11 +02:00
|
|
|
let cmd = format!("source {} && zinit self-update && zinit update --all", zshrc.display(),);
|
2020-03-06 10:57:30 +02:00
|
|
|
run_type.execute(zsh).args(&["-i", "-c", cmd.as_str()]).check_run()
|
2019-12-01 06:40:23 +00:00
|
|
|
}
|
|
|
|
|
|
2020-03-08 21:38:49 +02:00
|
|
|
pub fn run_oh_my_zsh(ctx: &ExecutionContext) -> Result<()> {
|
2020-01-29 10:22:31 +02:00
|
|
|
require("zsh")?;
|
2020-03-08 21:38:49 +02:00
|
|
|
let oh_my_zsh = ctx.base_dirs().home_dir().join(".oh-my-zsh").require()?;
|
2019-10-01 20:50:44 +03:00
|
|
|
|
|
|
|
|
print_separator("oh-my-zsh");
|
|
|
|
|
|
2020-03-08 21:38:49 +02:00
|
|
|
let mut custom_dir = PathBuf::from(
|
2020-06-24 13:32:48 +03:00
|
|
|
env::var::<_>("ZSH_CUSTOM")
|
|
|
|
|
.or_else(|_| Command::new("zsh").args(&["-c", "echo -n $ZSH_CUSTOM"]).check_output())?,
|
2020-03-08 21:38:49 +02:00
|
|
|
);
|
|
|
|
|
custom_dir.push("plugins");
|
|
|
|
|
|
|
|
|
|
debug!("oh-my-zsh custom dir: {}", custom_dir.display());
|
|
|
|
|
|
2020-04-03 11:47:51 +03:00
|
|
|
if let Ok(custom_plugins_dir) = fs::read_dir(custom_dir) {
|
|
|
|
|
let mut custom_plugins = Repositories::new(ctx.git());
|
|
|
|
|
|
|
|
|
|
for entry in custom_plugins_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)?;
|
|
|
|
|
}
|
2020-03-08 21:38:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ctx.run_type()
|
2020-01-29 10:35:31 +02:00
|
|
|
.execute("sh")
|
|
|
|
|
.env("ZSH", &oh_my_zsh)
|
|
|
|
|
.arg(&oh_my_zsh.join("tools/upgrade.sh"))
|
|
|
|
|
.check_run()
|
2019-10-01 20:50:44 +03:00
|
|
|
}
|