Move tmux to its own module
This commit is contained in:
@@ -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
49
src/tmux.rs
Normal 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);
|
||||
}
|
||||
43
src/unix.rs
43
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::<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") {
|
||||
|
||||
Reference in New Issue
Block a user