Add flag to invoke in tmux (fix #10)
This commit is contained in:
@@ -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:
|
||||
|
||||
|
||||
37
src/main.rs
37
src/main.rs
@@ -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};
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user