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;
|
|
|
|
|
use std::path::{Path, PathBuf};
|
2020-03-08 21:38:49 +02:00
|
|
|
use std::process::Command;
|
2020-07-22 06:19:08 +03:00
|
|
|
use walkdir::WalkDir;
|
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")?;
|
|
|
|
|
|
2020-09-05 00:05:54 +08:00
|
|
|
require("zr")?;
|
2019-10-01 20:50:44 +03:00
|
|
|
|
|
|
|
|
print_separator("zr");
|
|
|
|
|
|
2020-09-05 00:05:54 +08:00
|
|
|
let cmd = format!("source {} && zr --update", zshrc(base_dirs).display());
|
2022-10-23 11:34:30 +00: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");
|
|
|
|
|
|
2022-10-22 09:26:49 +00:00
|
|
|
let cmd = format!("source {} && (antigen selfupdate ; antigen update)", zshrc.display());
|
2022-10-23 11:34:30 +00:00
|
|
|
run_type.execute(zsh).args(["-l", "-c", cmd.as_str()]).check_run()
|
2019-10-01 20:50:44 +03:00
|
|
|
}
|
|
|
|
|
|
2022-02-18 15:01:34 +01:00
|
|
|
pub fn run_zgenom(base_dirs: &BaseDirs, run_type: RunType) -> Result<()> {
|
|
|
|
|
let zsh = require("zsh")?;
|
|
|
|
|
let zshrc = zshrc(base_dirs).require()?;
|
|
|
|
|
env::var("ZGEN_SOURCE")
|
|
|
|
|
.map(PathBuf::from)
|
|
|
|
|
.unwrap_or_else(|_| base_dirs.home_dir().join(".zgenom"))
|
|
|
|
|
.require()?;
|
|
|
|
|
|
|
|
|
|
print_separator("zgenom");
|
|
|
|
|
|
|
|
|
|
let cmd = format!("source {} && zgenom selfupdate && zgenom update", zshrc.display());
|
2022-10-23 11:34:30 +00:00
|
|
|
run_type.execute(zsh).args(["-l", "-c", cmd.as_str()]).check_run()
|
2022-02-18 15:01:34 +01: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)
|
2020-11-04 16:07:59 +02:00
|
|
|
.unwrap_or_else(|_| base_dirs.home_dir().join(".zplug"))
|
2019-10-01 20:50:44 +03:00
|
|
|
.require()?;
|
|
|
|
|
|
|
|
|
|
print_separator("zplug");
|
|
|
|
|
|
2022-10-23 11:34:30 +00: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()?;
|
|
|
|
|
|
2022-02-18 15:01:34 +01:00
|
|
|
env::var("ZINIT_HOME")
|
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(),);
|
2022-10-23 11:34:30 +00:00
|
|
|
run_type.execute(zsh).args(["-i", "-c", cmd.as_str()]).check_run()
|
2019-12-01 06:40:23 +00:00
|
|
|
}
|
|
|
|
|
|
2022-05-07 00:37:28 +09:00
|
|
|
pub fn run_zi(base_dirs: &BaseDirs, run_type: RunType) -> Result<()> {
|
|
|
|
|
let zsh = require("zsh")?;
|
|
|
|
|
let zshrc = zshrc(base_dirs).require()?;
|
|
|
|
|
|
2022-05-26 20:03:12 +03:00
|
|
|
base_dirs.home_dir().join(".zi").require()?;
|
2022-05-07 00:37:28 +09:00
|
|
|
|
|
|
|
|
print_separator("zi");
|
|
|
|
|
|
|
|
|
|
let cmd = format!("source {} && zi self-update && zi update --all", zshrc.display(),);
|
|
|
|
|
run_type.execute(zsh).args(["-i", "-c", &cmd]).check_run()
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-24 14:46:38 -05:00
|
|
|
pub fn run_zim(base_dirs: &BaseDirs, run_type: RunType) -> Result<()> {
|
|
|
|
|
let zsh = require("zsh")?;
|
|
|
|
|
env::var("ZIM_HOME")
|
|
|
|
|
.or_else(|_| {
|
|
|
|
|
Command::new("zsh")
|
2022-10-23 11:34:30 +00:00
|
|
|
.args(["-c", "[[ -n ${ZIM_HOME} ]] && print -n ${ZIM_HOME}"])
|
2020-10-24 14:46:38 -05:00
|
|
|
.check_output()
|
|
|
|
|
})
|
|
|
|
|
.map(PathBuf::from)
|
|
|
|
|
.unwrap_or_else(|_| base_dirs.home_dir().join(".zim"))
|
|
|
|
|
.require()?;
|
|
|
|
|
|
|
|
|
|
print_separator("zim");
|
|
|
|
|
|
|
|
|
|
run_type
|
|
|
|
|
.execute(zsh)
|
2022-10-23 11:34:30 +00:00
|
|
|
.args(["-i", "-c", "zimfw upgrade && zimfw update"])
|
2020-10-24 14:46:38 -05:00
|
|
|
.check_run()
|
|
|
|
|
}
|
|
|
|
|
|
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-07-22 06:19:08 +03:00
|
|
|
let custom_dir = env::var::<_>("ZSH_CUSTOM")
|
|
|
|
|
.or_else(|_| {
|
|
|
|
|
Command::new("zsh")
|
2022-10-23 11:34:30 +00:00
|
|
|
.args(["-c", "test $ZSH_CUSTOM && echo -n $ZSH_CUSTOM"])
|
2020-07-22 06:19:08 +03:00
|
|
|
.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
|
|
|
|
|
});
|
2020-03-08 21:38:49 +02:00
|
|
|
|
|
|
|
|
debug!("oh-my-zsh custom dir: {}", custom_dir.display());
|
|
|
|
|
|
2020-07-22 06:19:08 +03:00
|
|
|
let mut custom_repos = Repositories::new(ctx.git());
|
|
|
|
|
|
|
|
|
|
for entry in WalkDir::new(custom_dir).max_depth(2) {
|
|
|
|
|
let entry = entry?;
|
|
|
|
|
custom_repos.insert_if_repo(entry.path());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
custom_repos.remove(&oh_my_zsh.to_string_lossy());
|
|
|
|
|
if !custom_repos.is_empty() {
|
|
|
|
|
println!("Pulling custom plugins and themes");
|
|
|
|
|
ctx.git().multi_pull(&custom_repos, ctx)?;
|
2020-03-08 21:38:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ctx.run_type()
|
2020-12-01 11:28:52 +02:00
|
|
|
.execute("zsh")
|
2020-01-29 10:35:31 +02:00
|
|
|
.env("ZSH", &oh_my_zsh)
|
|
|
|
|
.arg(&oh_my_zsh.join("tools/upgrade.sh"))
|
2020-12-01 19:56:12 -08:00
|
|
|
.check_run_with_codes(&[80])
|
2019-10-01 20:50:44 +03:00
|
|
|
}
|