Compare commits
No commits in common. "5d60b35d0740cfb1ffc84be293e7e11111cd0e12" and "6b7c84b67387d33175ca266e9100e77a460ecb2a" have entirely different histories.
5d60b35d07
...
6b7c84b673
6 changed files with 7 additions and 41 deletions
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "remux"
|
name = "remux"
|
||||||
version = "0.3.1"
|
version = "0.3.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
authors = [ "Valerie Wolfe <sleeplessval@gmail.com>" ]
|
authors = [ "Valerie Wolfe <sleeplessval@gmail.com>" ]
|
||||||
description = "A friendly command shortener for tmux"
|
description = "A friendly command shortener for tmux"
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
//! commands accessible from within a session
|
//! commands accessible from within a session
|
||||||
use std::fs::read_to_string;
|
|
||||||
|
|
||||||
use pico_args::Arguments;
|
use pico_args::Arguments;
|
||||||
use tmux_interface::{
|
use tmux_interface::{
|
||||||
|
@ -9,10 +8,7 @@ use tmux_interface::{
|
||||||
|
|
||||||
use crate::{ error, flag, util };
|
use crate::{ error, flag, util };
|
||||||
|
|
||||||
const TMP_ROOT: &str = "/tmp/remux_root";
|
|
||||||
|
|
||||||
pub fn switch(pargs: &mut Arguments) {
|
pub fn switch(pargs: &mut Arguments) {
|
||||||
util::terminal_enforce();
|
|
||||||
// refuse to run outside a session
|
// refuse to run outside a session
|
||||||
util::session_enforce("switch");
|
util::session_enforce("switch");
|
||||||
|
|
||||||
|
@ -36,17 +32,3 @@ pub fn switch(pargs: &mut Arguments) {
|
||||||
.output().ok();
|
.output().ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn root() {
|
|
||||||
util::session_enforce("root");
|
|
||||||
|
|
||||||
let exec = commands::Run::new().shell_command("printf '#{session_path}' > ".to_string() + TMP_ROOT);
|
|
||||||
Tmux::new()
|
|
||||||
.add_command(exec)
|
|
||||||
.output().ok();
|
|
||||||
|
|
||||||
if let Ok(text) = read_to_string(TMP_ROOT) {
|
|
||||||
println!("{text}");
|
|
||||||
std::fs::remove_file(TMP_ROOT).ok();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -15,8 +15,6 @@ use tmux_interface::{
|
||||||
use crate::{ error, flag, util };
|
use crate::{ error, flag, util };
|
||||||
|
|
||||||
pub fn attach(pargs: &mut Arguments) {
|
pub fn attach(pargs: &mut Arguments) {
|
||||||
// must be run from terminal
|
|
||||||
util::terminal_enforce();
|
|
||||||
// don't allow unflagged nests
|
// don't allow unflagged nests
|
||||||
util::prevent_nest();
|
util::prevent_nest();
|
||||||
|
|
||||||
|
@ -61,7 +59,6 @@ pub fn attach(pargs: &mut Arguments) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn detach(pargs: &mut Arguments) {
|
pub fn detach(pargs: &mut Arguments) {
|
||||||
util::terminal_enforce();
|
|
||||||
// get target or fallback
|
// get target or fallback
|
||||||
let args = pargs.clone().finish();
|
let args = pargs.clone().finish();
|
||||||
let target: String;
|
let target: String;
|
||||||
|
@ -145,7 +142,6 @@ pub fn list() {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new(pargs: &mut Arguments) {
|
pub fn new(pargs: &mut Arguments) {
|
||||||
util::terminal_enforce();
|
|
||||||
// don't allow unflagged nesting
|
// don't allow unflagged nesting
|
||||||
util::prevent_nest();
|
util::prevent_nest();
|
||||||
|
|
||||||
|
|
|
@ -91,14 +91,6 @@ flags:
|
||||||
-n, --nest Create the session inside another session.
|
-n, --nest Create the session inside another session.
|
||||||
-t, --target <dir> Sets the target directory for the new session."),
|
-t, --target <dir> Sets the target directory for the new session."),
|
||||||
|
|
||||||
Some("root")
|
|
||||||
=>
|
|
||||||
println!("remux root
|
|
||||||
Print the session path (#{{session_path}}) to standard output.
|
|
||||||
Must be run from inside a session.
|
|
||||||
|
|
||||||
usage: remux root"),
|
|
||||||
|
|
||||||
Some("s" | "switch")
|
Some("s" | "switch")
|
||||||
=>
|
=>
|
||||||
println!("remux switch
|
println!("remux switch
|
||||||
|
|
10
src/main.rs
10
src/main.rs
|
@ -1,4 +1,7 @@
|
||||||
use std::env::{ set_var, var };
|
use std::{
|
||||||
|
env::{ set_var, var },
|
||||||
|
io::{ stdout, IsTerminal }
|
||||||
|
};
|
||||||
|
|
||||||
use pico_args::Arguments;
|
use pico_args::Arguments;
|
||||||
|
|
||||||
|
@ -36,6 +39,8 @@ fn main() {
|
||||||
set_var("TMUX", "");
|
set_var("TMUX", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !stdout().is_terminal() { error::not_terminal(); }
|
||||||
|
|
||||||
let subcommand = args.subcommand().unwrap();
|
let subcommand = args.subcommand().unwrap();
|
||||||
|
|
||||||
// invoke subcommand function
|
// invoke subcommand function
|
||||||
|
@ -59,9 +64,6 @@ fn main() {
|
||||||
Some("n" | "new")
|
Some("n" | "new")
|
||||||
=> command::share::new(&mut args),
|
=> command::share::new(&mut args),
|
||||||
|
|
||||||
Some("root")
|
|
||||||
=> command::session::root(),
|
|
||||||
|
|
||||||
Some("s" | "switch")
|
Some("s" | "switch")
|
||||||
=> command::session::switch(&mut args),
|
=> command::session::switch(&mut args),
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
use std::{
|
use std::{
|
||||||
env::{ current_dir, var },
|
env::{ current_dir, var },
|
||||||
io::{ stdout, IsTerminal },
|
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
process::exit
|
process::exit
|
||||||
};
|
};
|
||||||
|
@ -50,11 +49,6 @@ pub fn session_exists<S: Into<String>>(target: S) -> bool {
|
||||||
.success()
|
.success()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// enforce a command is being run in a terminal
|
|
||||||
pub fn terminal_enforce() {
|
|
||||||
if !stdout().is_terminal() { error::not_terminal(); }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// attempt to return the repo name or exit
|
/// attempt to return the repo name or exit
|
||||||
pub fn repo_fallback() -> String {
|
pub fn repo_fallback() -> String {
|
||||||
let repo = repo_root(current_dir().unwrap());
|
let repo = repo_root(current_dir().unwrap());
|
||||||
|
|
Loading…
Reference in a new issue