Files
topgrade/src/unix.rs

106 lines
2.9 KiB
Rust
Raw Normal View History

2018-08-26 16:12:59 +03:00
use super::executor::Executor;
2018-08-19 14:45:23 +03:00
use super::terminal::Terminal;
2018-07-07 09:18:53 +03:00
use super::utils::{which, Check, PathExt};
use directories::BaseDirs;
2018-08-19 14:45:23 +03:00
use failure::Error;
2018-06-28 12:16:54 +03:00
use std::env;
use std::os::unix::process::CommandExt;
use std::process::Command;
2018-08-26 16:12:59 +03:00
pub fn run_zplug(base_dirs: &BaseDirs, terminal: &mut Terminal, dry_run: bool) -> Option<(&'static str, bool)> {
2018-08-19 14:45:23 +03:00
if let Some(zsh) = which("zsh") {
if base_dirs.home_dir().join(".zplug").exists() {
terminal.print_separator("zplug");
2018-06-28 12:16:54 +03:00
2018-08-19 14:45:23 +03:00
let success = || -> Result<(), Error> {
2018-08-26 16:12:59 +03:00
Executor::new(zsh, dry_run)
2018-08-19 14:45:23 +03:00
.args(&["-c", "source ~/.zshrc && zplug update"])
.spawn()?
.wait()?
.check()?;
Ok(())
}().is_ok();
2018-06-28 12:16:54 +03:00
2018-08-19 14:45:23 +03:00
return Some(("zplug", success));
}
}
2018-07-03 14:31:25 +03:00
2018-08-19 14:45:23 +03:00
None
2018-07-03 14:31:25 +03:00
}
2018-08-26 16:12:59 +03:00
pub fn run_fisherman(base_dirs: &BaseDirs, terminal: &mut Terminal, dry_run: bool) -> Option<(&'static str, bool)> {
2018-08-26 16:53:19 +03:00
if let Some(fish) = which("fish") {
2018-08-19 14:45:23 +03:00
if base_dirs.home_dir().join(".config/fish/functions/fisher.fish").exists() {
terminal.print_separator("fisherman");
let success = || -> Result<(), Error> {
2018-08-26 16:12:59 +03:00
Executor::new(fish, dry_run)
2018-08-19 14:45:23 +03:00
.args(&["-c", "fisher update"])
.spawn()?
.wait()?
.check()?;
Ok(())
}().is_ok();
return Some(("fisherman", success));
}
}
2018-06-28 12:16:54 +03:00
2018-08-19 14:45:23 +03:00
None
2018-06-28 12:16:54 +03:00
}
2018-08-26 16:12:59 +03:00
pub fn run_tpm(base_dirs: &BaseDirs, terminal: &mut Terminal, dry_run: bool) -> Option<(&'static str, bool)> {
2018-08-19 14:45:23 +03:00
if let Some(tpm) = base_dirs
2018-07-07 09:18:53 +03:00
.home_dir()
.join(".tmux/plugins/tpm/bin/update_plugins")
.if_exists()
2018-08-19 14:45:23 +03:00
{
terminal.print_separator("tmux plugins");
let success = || -> Result<(), Error> {
2018-08-26 16:12:59 +03:00
Executor::new(&tpm, dry_run).arg("all").spawn()?.wait()?.check()?;
2018-08-19 14:45:23 +03:00
Ok(())
}().is_ok();
return Some(("tmux", success));
}
None
2018-06-28 12:16:54 +03:00
}
pub fn run_in_tmux() -> ! {
2018-07-07 09:18:53 +03:00
let tmux = which("tmux").expect("Could not find tmux");
2018-06-28 12:16:54 +03:00
let err = Command::new(tmux)
.args(&[
"new-session",
"-s",
"topgrade",
"-n",
"topgrade",
&env::args().collect::<Vec<String>>().join(" "),
";",
"set",
"remain-on-exit",
"on",
])
.exec();
panic!("{:?}", err);
}
2018-08-19 14:45:23 +03:00
#[must_use]
2018-08-26 16:12:59 +03:00
pub fn run_homebrew(terminal: &mut Terminal, dry_run: bool) -> Option<(&'static str, bool)> {
2018-08-19 14:45:23 +03:00
if let Some(brew) = which("brew") {
terminal.print_separator("Brew");
let inner = || -> Result<(), Error> {
2018-08-26 16:12:59 +03:00
Executor::new(&brew, dry_run).arg("update").spawn()?.wait()?.check()?;
Executor::new(&brew, dry_run).arg("upgrade").spawn()?.wait()?.check()?;
2018-08-19 14:45:23 +03:00
Ok(())
};
return Some(("Brew", inner().is_ok()));
}
None
}