Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Add flag to invoke in tmux (fix #10)
Browse files Browse the repository at this point in the history
  • Loading branch information
r-darwish committed Jun 20, 2018
1 parent 2ee068f commit d434073
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ Just run `topgrade`. It will run the following steps:
* *Linux*: Run [needrestart](https://github.com/liske/needrestart)
* *macOS*: Upgrade App Store applications

## Flags
* `-t/--tmux` - Topgrade will launch itself in a new tmux session. This flag has no effect if
Topgrade already runs inside tmux. This is useful when using topgrade on remote systems.

## Customization
You can place a configuration file at `~/.config/topgrade.toml`. Here's an example:

Expand Down
37 changes: 35 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,18 @@ mod terminal;
mod utils;
mod vim;

use clap::App;
use clap::{App, Arg};
use config::Config;
use failure::Error;
use git::{Git, Repositories};
use report::{Report, Reporter};
use std::env;
use std::env::home_dir;
#[cfg(unix)]
use std::os::unix::process::CommandExt;
use std::path::PathBuf;
use std::process::exit;
use std::process::Command;
use steps::*;
use terminal::Terminal;
use utils::{home_path, is_ancestor};
Expand All @@ -53,11 +57,40 @@ fn tpm() -> Option<PathBuf> {
}

fn run() -> Result<(), Error> {
let _ = App::new("Topgrade")
let matches = App::new("Topgrade")
.version(crate_version!())
.about("Upgrade all the things")
.arg(
Arg::with_name("tmux")
.help("Invoke inside tmux")
.short("t")
.long("tmux"),
)
.get_matches();

if matches.is_present("tmux") && !env::var("TMUX").is_ok() {
if cfg!(unix) {
let tmux = utils::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);
} else {
panic!("This flag is only implemented in Unix systems");
}
}

env_logger::init();
let git = Git::new();
let mut git_repos = Repositories::new(&git);
Expand Down

0 comments on commit d434073

Please sign in to comment.