Files
topgrade/src/steps/zsh.rs

88 lines
2.6 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_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
}
pub fn run_zplugin(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()?;
env::var("ZPLGM[HOME_DIR]")
.map(PathBuf::from)
.unwrap_or_else(|_| base_dirs.home_dir().join(".zplugin"))
.require()?;
print_separator("zplugin");
let cmd = format!(
"source {} && zplugin self-update && zplugin update --all",
zshrc.display()
);
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
}