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

View File

@@ -21,6 +21,8 @@ mod linux;
#[cfg(target_os = "macos")]
mod macos;
#[cfg(unix)]
mod tmux;
#[cfg(unix)]
mod unix;
#[cfg(target_os = "windows")]
mod windows;
@@ -101,7 +103,7 @@ fn run() -> Result<(), Error> {
if matches.is_present("tmux") && env::var("TMUX").is_err() {
#[cfg(unix)]
{
unix::run_in_tmux();
tmux::run_in_tmux();
}
}
@@ -193,7 +195,7 @@ fn run() -> Result<(), Error> {
&mut terminal,
));
report.push_result(execute(
|terminal| unix::run_tpm(&base_dirs, terminal, dry_run),
|terminal| tmux::run_tpm(&base_dirs, terminal, dry_run),
&mut terminal,
));
}

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);
}

View File

@@ -1,11 +1,8 @@
use super::executor::Executor;
use super::terminal::Terminal;
use super::utils::{which, Check, PathExt};
use super::utils::{which, Check};
use directories::BaseDirs;
use failure::Error;
use std::env;
use std::os::unix::process::CommandExt;
use std::process::Command;
pub fn run_zplug(base_dirs: &BaseDirs, terminal: &mut Terminal, dry_run: bool) -> Option<(&'static str, bool)> {
if let Some(zsh) = which("zsh") {
@@ -49,44 +46,6 @@ pub fn run_fisherman(base_dirs: &BaseDirs, terminal: &mut Terminal, dry_run: boo
None
}
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);
}
#[must_use]
pub fn run_homebrew(terminal: &mut Terminal, dry_run: bool) -> Option<(&'static str, bool)> {
if let Some(brew) = which("brew") {