From 6f4d99aa40f8dfd0e8513af4d994af18c684f8d4 Mon Sep 17 00:00:00 2001 From: Roey Darwish Dror Date: Tue, 4 Sep 2018 11:05:54 +0300 Subject: [PATCH] Move tmux to its own module --- src/main.rs | 6 ++++-- src/tmux.rs | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ src/unix.rs | 43 +------------------------------------------ 3 files changed, 54 insertions(+), 44 deletions(-) create mode 100644 src/tmux.rs diff --git a/src/main.rs b/src/main.rs index ad28de2f..1fc001e1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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, )); } diff --git a/src/tmux.rs b/src/tmux.rs new file mode 100644 index 00000000..f72ba5de --- /dev/null +++ b/src/tmux.rs @@ -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::>().join(" "), + ";", + "set", + "remain-on-exit", + "on", + ]) + .exec(); + + panic!("{:?}", err); +} diff --git a/src/unix.rs b/src/unix.rs index da16284d..0d3089eb 100644 --- a/src/unix.rs +++ b/src/unix.rs @@ -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::>().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") {