From 7728819133bfa451b05fd12d18fcd723dfc01348 Mon Sep 17 00:00:00 2001 From: Roey Darwish Dror Date: Sun, 26 Feb 2023 23:45:43 +0200 Subject: [PATCH] Support antidote (#368) --- src/main.rs | 1 + src/steps/zsh.rs | 26 ++++++++++++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 4cedf194..abc132cf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -317,6 +317,7 @@ For more information about this issue see https://askubuntu.com/questions/110969 { runner.execute(Step::Shell, "zr", || zsh::run_zr(&base_dirs, run_type))?; runner.execute(Step::Shell, "antibody", || zsh::run_antibody(run_type))?; + runner.execute(Step::Shell, "antidote", || zsh::run_antidote(&ctx))?; runner.execute(Step::Shell, "antigen", || zsh::run_antigen(&base_dirs, run_type))?; runner.execute(Step::Shell, "zgenom", || zsh::run_zgenom(&base_dirs, run_type))?; runner.execute(Step::Shell, "zplug", || zsh::run_zplug(&base_dirs, run_type))?; diff --git a/src/steps/zsh.rs b/src/steps/zsh.rs index 4ffdcc30..9f4c7251 100644 --- a/src/steps/zsh.rs +++ b/src/steps/zsh.rs @@ -1,5 +1,5 @@ use std::env; -use std::path::{Path, PathBuf}; +use std::path::PathBuf; use std::process::Command; use color_eyre::eyre::Result; @@ -25,10 +25,28 @@ pub fn run_zr(base_dirs: &BaseDirs, run_type: RunType) -> Result<()> { run_type.execute(zsh).args(["-l", "-c", cmd.as_str()]).status_checked() } -pub fn zshrc(base_dirs: &BaseDirs) -> PathBuf { +fn zdotdir(base_dirs: &BaseDirs) -> PathBuf { env::var("ZDOTDIR") - .map(|p| Path::new(&p).join(".zshrc")) - .unwrap_or_else(|_| base_dirs.home_dir().join(".zshrc")) + .map(PathBuf::from) + .unwrap_or_else(|_| base_dirs.home_dir().to_path_buf()) +} + +pub fn zshrc(base_dirs: &BaseDirs) -> PathBuf { + zdotdir(base_dirs).join(".zshrc") +} + +pub fn run_antidote(ctx: &ExecutionContext) -> Result<()> { + let zsh = require("zsh")?; + let mut antidote = zdotdir(ctx.base_dirs()).join(".antidote").require()?; + antidote.push("antidote.zsh"); + + print_separator("antidote"); + + ctx.run_type() + .execute(zsh) + .arg("-c") + .arg(format!("source {} && antidote update", antidote.display())) + .status_checked() } pub fn run_antibody(run_type: RunType) -> Result<()> {