2019-02-27 10:06:54 +02:00
|
|
|
use crate::error::Error;
|
2019-02-03 10:12:54 +02:00
|
|
|
use crate::executor::{CommandExt, RunType};
|
2018-12-15 21:52:21 +02:00
|
|
|
use crate::terminal::print_separator;
|
2019-02-27 10:31:30 +02:00
|
|
|
use crate::utils::{require, PathExt};
|
2018-07-07 09:18:53 +03:00
|
|
|
use directories::BaseDirs;
|
2019-02-26 02:40:51 -08:00
|
|
|
use std::env;
|
2019-02-26 11:53:22 -08:00
|
|
|
use std::path::{Path, PathBuf};
|
2019-02-03 10:12:54 +02:00
|
|
|
use std::process::Command;
|
2019-02-26 02:34:51 -08:00
|
|
|
|
2019-02-27 10:31:30 +02:00
|
|
|
pub fn run_zplug(base_dirs: &BaseDirs, run_type: RunType) -> Result<(), Error> {
|
|
|
|
|
let zsh = require("zsh")?;
|
2019-02-26 02:34:51 -08:00
|
|
|
|
2019-02-27 10:31:30 +02:00
|
|
|
env::var("ZPLUG_HOME")
|
2019-02-26 11:53:22 -08:00
|
|
|
.map(PathBuf::from)
|
2019-02-27 10:31:30 +02:00
|
|
|
.unwrap_or_else(|_| base_dirs.home_dir().join("zplug"))
|
|
|
|
|
.require()?;
|
2018-06-28 12:16:54 +03:00
|
|
|
|
2019-02-27 10:31:30 +02:00
|
|
|
let zshrc = env::var("ZDOTDIR")
|
|
|
|
|
.map(|p| Path::new(&p).join(".zshrc"))
|
|
|
|
|
.unwrap_or_else(|_| base_dirs.home_dir().join(".zshrc"))
|
|
|
|
|
.require()?;
|
2018-07-03 14:31:25 +03:00
|
|
|
|
2019-03-10 01:25:07 -08:00
|
|
|
print_separator("zplug");
|
|
|
|
|
|
2019-02-27 10:31:30 +02:00
|
|
|
let cmd = format!("source {} && zplug update", zshrc.display());
|
|
|
|
|
run_type.execute(zsh).args(&["-c", cmd.as_str()]).check_run()
|
2018-07-03 14:31:25 +03:00
|
|
|
}
|
|
|
|
|
|
2019-02-27 10:31:30 +02:00
|
|
|
pub fn run_fisher(base_dirs: &BaseDirs, run_type: RunType) -> Result<(), Error> {
|
|
|
|
|
let fish = require("fish")?;
|
|
|
|
|
base_dirs
|
|
|
|
|
.home_dir()
|
|
|
|
|
.join(".config/fish/functions/fisher.fish")
|
|
|
|
|
.require()?;
|
2019-04-16 08:37:56 +03:00
|
|
|
|
|
|
|
|
print_separator("Fisher");
|
2019-02-27 10:31:30 +02:00
|
|
|
run_type
|
|
|
|
|
.execute(&fish)
|
|
|
|
|
.args(&["-c", "fisher self-update"])
|
|
|
|
|
.check_run()?;
|
2019-04-06 09:46:50 +03:00
|
|
|
|
2019-02-27 10:31:30 +02:00
|
|
|
run_type.execute(&fish).args(&["-c", "fisher"]).check_run()
|
2018-06-28 12:16:54 +03:00
|
|
|
}
|
|
|
|
|
|
2018-08-19 14:45:23 +03:00
|
|
|
#[must_use]
|
2019-02-27 10:31:30 +02:00
|
|
|
pub fn run_homebrew(cleanup: bool, run_type: RunType) -> Result<(), Error> {
|
|
|
|
|
let brew = require("brew")?;
|
|
|
|
|
print_separator("Brew");
|
|
|
|
|
|
|
|
|
|
run_type.execute(&brew).arg("update").check_run()?;
|
|
|
|
|
run_type.execute(&brew).arg("upgrade").check_run()?;
|
|
|
|
|
|
|
|
|
|
let cask_upgrade_exists = Command::new(&brew)
|
|
|
|
|
.args(&["--repository", "buo/cask-upgrade"])
|
|
|
|
|
.check_output()
|
|
|
|
|
.map(|p| Path::new(p.trim()).exists())?;
|
|
|
|
|
|
|
|
|
|
if cask_upgrade_exists {
|
2019-03-12 19:17:21 +02:00
|
|
|
run_type.execute(&brew).args(&["cu", "-ay"]).check_run()?;
|
2019-02-27 10:31:30 +02:00
|
|
|
} else {
|
|
|
|
|
run_type.execute(&brew).args(&["cask", "upgrade"]).check_run()?;
|
|
|
|
|
}
|
2018-08-19 14:45:23 +03:00
|
|
|
|
2019-02-27 10:31:30 +02:00
|
|
|
if cleanup {
|
|
|
|
|
run_type.execute(&brew).arg("cleanup").check_run()?;
|
2018-08-19 14:45:23 +03:00
|
|
|
}
|
|
|
|
|
|
2019-02-27 10:31:30 +02:00
|
|
|
Ok(())
|
2018-08-19 14:45:23 +03:00
|
|
|
}
|
2018-10-21 13:05:49 +03:00
|
|
|
|
|
|
|
|
#[must_use]
|
2019-02-27 10:31:30 +02:00
|
|
|
pub fn run_nix(run_type: RunType) -> Result<(), Error> {
|
|
|
|
|
let nix = require("nix")?;
|
2019-04-06 09:46:59 +03:00
|
|
|
let nix_env = require("nix-env")?;
|
2018-10-21 13:05:49 +03:00
|
|
|
|
2019-02-27 10:31:30 +02:00
|
|
|
print_separator("Nix");
|
|
|
|
|
run_type.execute(&nix).arg("upgrade-nix").check_run()?;
|
|
|
|
|
run_type.execute(&nix_env).arg("--upgrade").check_run()
|
2018-10-21 13:05:49 +03:00
|
|
|
}
|
2019-02-19 08:47:01 +02:00
|
|
|
|
|
|
|
|
pub fn run_pearl(run_type: RunType) -> Result<(), Error> {
|
|
|
|
|
let pearl = require("pearl")?;
|
|
|
|
|
print_separator("pearl");
|
|
|
|
|
|
|
|
|
|
run_type.execute(&pearl).arg("update").check_run()
|
|
|
|
|
}
|