added search and quiet mode to 'list' command and wrote a completion function
This commit is contained in:
parent
b7b893d55c
commit
1b51633d4f
4 changed files with 50 additions and 22 deletions
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "remux"
|
name = "remux"
|
||||||
version = "0.3.5"
|
version = "0.3.6"
|
||||||
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"
|
||||||
|
|
19
bash_completion/remux
Normal file
19
bash_completion/remux
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
_remux() {
|
||||||
|
local word
|
||||||
|
COMPREPLY=()
|
||||||
|
word="${COMP_WORDS[COMP_CWORD]}"
|
||||||
|
|
||||||
|
case $COMP_CWORD in
|
||||||
|
1)
|
||||||
|
COMPREPLY=( `compgen -W 'attach detach has help list new path switch title' -- "$word"` )
|
||||||
|
;;
|
||||||
|
2)
|
||||||
|
COMPREPLY=( `compgen -W "$(remux l -q $word)"` )
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
complete -F _remux remux
|
||||||
|
|
|
@ -56,7 +56,7 @@ pub fn attach(state: &mut State) {
|
||||||
state.nest_deinit();
|
state.nest_deinit();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn context_action(state: &State) {
|
pub fn context_action(state: &mut State) {
|
||||||
if !state.session {
|
if !state.session {
|
||||||
if let Some(repository) = &state.repository {
|
if let Some(repository) = &state.repository {
|
||||||
let target = repository.name.clone();
|
let target = repository.name.clone();
|
||||||
|
@ -72,7 +72,7 @@ pub fn context_action(state: &State) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// fallback behavior is list
|
// fallback behavior is list
|
||||||
list(&state);
|
list(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn detach(state: &mut State) {
|
pub fn detach(state: &mut State) {
|
||||||
|
@ -114,10 +114,12 @@ pub fn has(state: &mut State) {
|
||||||
exit( if success { 0 } else { 1 });
|
exit( if success { 0 } else { 1 });
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn list(state: &State) {
|
pub fn list(state: &mut State) {
|
||||||
// get session list
|
// get session list
|
||||||
let sessions = util::get_sessions().unwrap_or(Vec::new());
|
let sessions = util::get_sessions().unwrap_or(Vec::new());
|
||||||
|
|
||||||
|
let search = state.target();
|
||||||
|
|
||||||
// handle empty case
|
// handle empty case
|
||||||
if sessions.len() == 0 {
|
if sessions.len() == 0 {
|
||||||
println!("no sessions");
|
println!("no sessions");
|
||||||
|
@ -129,25 +131,32 @@ pub fn list(state: &State) {
|
||||||
let current_symbol = env_var(env::CURRENT_SYMBOL);
|
let current_symbol = env_var(env::CURRENT_SYMBOL);
|
||||||
|
|
||||||
// pretty print session list
|
// pretty print session list
|
||||||
println!("sessions:");
|
if !state.flags.quiet { println!("sessions:"); }
|
||||||
for session in sessions.into_iter() {
|
for session in sessions {
|
||||||
let name = session.name.unwrap_or("[untitled]".to_string());
|
let name = session.name.unwrap_or("[untitled]".to_string());
|
||||||
let id = session.id.unwrap();
|
|
||||||
|
|
||||||
let attached = session.attached.unwrap_or(0) > 0;
|
if search.is_some() && !name.starts_with(search.as_ref().unwrap()) { continue; }
|
||||||
let current = Some(name.clone()) == state.title;
|
|
||||||
|
|
||||||
println!(
|
if !state.flags.quiet {
|
||||||
" {current} {name}{reset} ({bold}{blue}{id}{reset}) {bold}{green}{attach}{reset}",
|
let id = session.id.unwrap();
|
||||||
// values
|
|
||||||
attach = if attached { attach_symbol.clone() } else { "".to_string() },
|
let attached = session.attached.unwrap_or(0) > 0;
|
||||||
current = if current { current_symbol.clone() } else { " ".to_string() },
|
let current = Some(name.clone()) == state.title;
|
||||||
// formatting
|
|
||||||
bold = style::Bold,
|
println!(
|
||||||
blue = color::Fg(color::Blue),
|
" {current} {name}{reset} ({bold}{blue}{id}{reset}) {bold}{green}{attach}{reset}",
|
||||||
green = color::Fg(color::LightGreen),
|
// values
|
||||||
reset = style::Reset,
|
attach = if attached { attach_symbol.clone() } else { "".to_string() },
|
||||||
);
|
current = if current { current_symbol.clone() } else { " ".to_string() },
|
||||||
|
// formatting
|
||||||
|
bold = style::Bold,
|
||||||
|
blue = color::Fg(color::Blue),
|
||||||
|
green = color::Fg(color::LightGreen),
|
||||||
|
reset = style::Reset,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
print!("{name} ");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ fn main() {
|
||||||
Some("help")
|
Some("help")
|
||||||
=> help(&mut args),
|
=> help(&mut args),
|
||||||
None
|
None
|
||||||
=> command::share::context_action(&state),
|
=> command::share::context_action(&mut state),
|
||||||
|
|
||||||
Some("a" | "attach")
|
Some("a" | "attach")
|
||||||
=> command::share::attach(&mut state),
|
=> command::share::attach(&mut state),
|
||||||
|
@ -50,7 +50,7 @@ fn main() {
|
||||||
=> command::share::has(&mut state),
|
=> command::share::has(&mut state),
|
||||||
|
|
||||||
Some("l" | "ls" | "list")
|
Some("l" | "ls" | "list")
|
||||||
=> command::share::list(&state),
|
=> command::share::list(&mut state),
|
||||||
|
|
||||||
Some("n" | "new")
|
Some("n" | "new")
|
||||||
=> command::share::new(&mut state),
|
=> command::share::new(&mut state),
|
||||||
|
|
Loading…
Reference in a new issue