Files
topgrade/src/steps/zsh.rs

103 lines
2.9 KiB
Rust
Raw Normal View History

2019-10-01 20:50:44 +03:00
use crate::executor::RunType;
use crate::terminal::print_separator;
use crate::utils::{require, PathExt};
use anyhow::Result;
2019-10-01 20:50:44 +03:00
use directories::BaseDirs;
use std::env;
use std::path::{Path, PathBuf};
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"))
}
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()
}
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
}
pub fn run_zplug(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("ZPLUG_HOME")
.map(PathBuf::from)
.unwrap_or_else(|_| base_dirs.home_dir().join("zplug"))
.require()?;
print_separator("zplug");
let cmd = format!("source {} && zplug 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
}
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-15 08:11:45 -06:00
env::var("ZPFX").map(PathBuf::from).unwrap().require()?;
2019-12-01 06:40:23 +00:00
2020-02-12 23:59:28 -06:00
print_separator("zinit");
2019-12-01 06:40:23 +00:00
2020-02-15 08:11:45 -06:00
// Check whether this is a pre- or post- renaming installation
let zcommand = if Path::new(&base_dirs.home_dir().join(".zinit")).exists() {
"zinit"
} else {
"zplugin"
};
let cmd = format!(
"source {} && {} self-update && {} update --all",
zshrc.display(),
zcommand,
zcommand
);
2020-01-16 10:23:37 +02:00
run_type.execute(zsh).args(&["-l", "-c", cmd.as_str()]).check_run()
2019-12-01 06:40:23 +00:00
}
pub fn run_oh_my_zsh(base_dirs: &BaseDirs, run_type: RunType) -> Result<()> {
2020-01-29 10:22:31 +02:00
require("zsh")?;
let oh_my_zsh = base_dirs.home_dir().join(".oh-my-zsh").require()?;
2019-10-01 20:50:44 +03:00
print_separator("oh-my-zsh");
2020-01-29 10:35:31 +02:00
run_type
.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
}