added contextual action as default command
This commit is contained in:
parent
222f929fd4
commit
ac97336f13
3 changed files with 20 additions and 2 deletions
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "remux"
|
name = "remux"
|
||||||
version = "0.3.1"
|
version = "0.3.2"
|
||||||
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"
|
||||||
|
|
|
@ -64,6 +64,23 @@ pub fn attach(pargs: &mut Arguments) {
|
||||||
tmux.output().ok();
|
tmux.output().ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn context_action() {
|
||||||
|
let repo = util::repo_root(std::env::current_dir().unwrap());
|
||||||
|
if !env::tmux() && repo.is_some() {
|
||||||
|
let target = util::repo_fallback();
|
||||||
|
let mut args = Arguments::from_vec( vec![(&target).into()] );
|
||||||
|
if util::session_exists(&target) {
|
||||||
|
attach(&mut args);
|
||||||
|
} else {
|
||||||
|
new(&mut args);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
// fallback behavior is list
|
||||||
|
list();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn detach(pargs: &mut Arguments) {
|
pub fn detach(pargs: &mut Arguments) {
|
||||||
util::terminal_enforce();
|
util::terminal_enforce();
|
||||||
// get target or fallback
|
// get target or fallback
|
||||||
|
|
|
@ -43,6 +43,8 @@ fn main() {
|
||||||
match subcommand.as_deref() {
|
match subcommand.as_deref() {
|
||||||
Some("help")
|
Some("help")
|
||||||
=> help(&mut args),
|
=> help(&mut args),
|
||||||
|
None
|
||||||
|
=> command::share::context_action(),
|
||||||
|
|
||||||
Some("a" | "attach")
|
Some("a" | "attach")
|
||||||
=> command::share::attach(&mut args),
|
=> command::share::attach(&mut args),
|
||||||
|
@ -53,7 +55,6 @@ fn main() {
|
||||||
Some("h" | "has")
|
Some("h" | "has")
|
||||||
=> command::share::has(&mut args),
|
=> command::share::has(&mut args),
|
||||||
|
|
||||||
None |
|
|
||||||
Some("l" | "ls" | "list")
|
Some("l" | "ls" | "list")
|
||||||
=> command::share::list(),
|
=> command::share::list(),
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue