Move tmux to its own module

This commit is contained in:
Roey Darwish Dror
2018-09-04 11:05:54 +03:00
parent bad68804ed
commit 6f4d99aa40
3 changed files with 54 additions and 44 deletions

49
src/tmux.rs Normal file
View File

@@ -0,0 +1,49 @@
use super::executor::Executor;
use super::terminal::Terminal;
use super::utils::which;
use super::utils::{Check, PathExt};
use directories::BaseDirs;
use failure::Error;
use std::env;
use std::os::unix::process::CommandExt;
use std::process::Command;
pub fn run_tpm(base_dirs: &BaseDirs, terminal: &mut Terminal, dry_run: bool) -> Option<(&'static str, bool)> {
if let Some(tpm) = base_dirs
.home_dir()
.join(".tmux/plugins/tpm/bin/update_plugins")
.if_exists()
{
terminal.print_separator("tmux plugins");
let success = || -> Result<(), Error> {
Executor::new(&tpm, dry_run).arg("all").spawn()?.wait()?.check()?;
Ok(())
}().is_ok();
return Some(("tmux", success));
}
None
}
pub fn run_in_tmux() -> ! {
let tmux = which("tmux").expect("Could not find tmux");
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);
}