mirror of
https://github.com/FliegendeWurst/tmux-thumbs.git
synced 2024-11-09 16:00:35 +00:00
Custom commands
This commit is contained in:
parent
50b5c328d7
commit
139808e7ef
@ -65,11 +65,14 @@ FLAGS:
|
||||
OPTIONS:
|
||||
-a, --alphabet <alphabet> Sets the alphabet [default: qwerty]
|
||||
--bg-color <background_color> Sets the background color for matches [default: black]
|
||||
--command <command> Pick command [default: tmux set-buffer {}]
|
||||
--fg-color <foreground_color> Sets the foregroud color for matches [default: green]
|
||||
--hint-bg-color <hint_background_color> Sets the background color for hints [default: black]
|
||||
--hint-fg-color <hint_foreground_color> Sets the foregroud color for hints [default: yellow]
|
||||
-p, --position <position> Hint position [default: left]
|
||||
--select-fg-color <select_foreground_color> Sets the foregroud color for selection [default: blue]
|
||||
--upcase-command <upcase_command> Upcase command [default: tmux paste-buffer]
|
||||
|
||||
```
|
||||
|
||||
### Arguments
|
||||
@ -78,6 +81,8 @@ OPTIONS:
|
||||
- **reverse:** Choose in which direction you want to assign hints. Useful to get shorter hints closer.
|
||||
- **unique:** Choose if you want to assign the same hint for the same matched strings.
|
||||
- **position:** Choose where do you want to show the hint in the matched string. Options (left, right). Default [left]
|
||||
- **command:** Choose whish command execute when you press a hint
|
||||
- **upcase-command:** Choose which command execute when you press a upcase hint
|
||||
|
||||
- **bg-color:** Sets the background color for matches [default: black]
|
||||
- **fg-color:** Sets the foregroud color for matches [default: green]
|
||||
|
47
src/main.rs
47
src/main.rs
@ -64,6 +64,14 @@ fn app_args<'a> () -> clap::ArgMatches<'a> {
|
||||
.long("position")
|
||||
.default_value("left")
|
||||
.short("p"))
|
||||
.arg(Arg::with_name("command")
|
||||
.help("Pick command")
|
||||
.long("command")
|
||||
.default_value("tmux set-buffer {}"))
|
||||
.arg(Arg::with_name("upcase_command")
|
||||
.help("Upcase command")
|
||||
.long("upcase-command")
|
||||
.default_value("tmux paste-buffer"))
|
||||
.get_matches();
|
||||
}
|
||||
|
||||
@ -80,13 +88,21 @@ fn main() {
|
||||
let hint_background_color = colors::get_color(args.value_of("hint_background_color").unwrap());
|
||||
let select_foreground_color = colors::get_color(args.value_of("select_foreground_color").unwrap());
|
||||
|
||||
let command = args.value_of("command").unwrap();
|
||||
let upcase_command = args.value_of("upcase_command").unwrap();
|
||||
|
||||
let execution = exec_command(format!("tmux capture-pane -e -J -p"));
|
||||
let output = String::from_utf8_lossy(&execution.stdout);
|
||||
let lines = output.split("\n").collect::<Vec<&str>>();
|
||||
|
||||
let mut state = state::State::new(&lines, alphabet);
|
||||
let mut selected;
|
||||
let mut paste = false;
|
||||
|
||||
let mut typed_hint: String = "".to_owned();
|
||||
let matches = state.matches(reverse, unique);
|
||||
let longest_hint = matches.iter().filter(|&m| m.hint.clone().is_some()).last().unwrap().hint.clone().expect("Unknown hint").len();
|
||||
|
||||
{
|
||||
let mut rustbox = match RustBox::init(Default::default()) {
|
||||
Result::Ok(v) => v,
|
||||
@ -104,12 +120,8 @@ fn main() {
|
||||
}
|
||||
}
|
||||
|
||||
let mut typed_hint: String = "".to_owned();
|
||||
let matches = state.matches(reverse, unique);
|
||||
let longest_hint = matches.iter().filter(|&m| m.hint.clone().is_some()).last().unwrap().hint.clone().expect("Unknown hint").len();
|
||||
|
||||
loop {
|
||||
let mut selected = matches.last();
|
||||
selected = matches.last();
|
||||
|
||||
match matches.iter().enumerate().find(|&h| h.0 == state.skip) {
|
||||
Some(hm) => {
|
||||
@ -147,17 +159,15 @@ fn main() {
|
||||
match key {
|
||||
Key::Esc => { break; }
|
||||
Key::Enter => {
|
||||
let mut choosen = matches.first().unwrap();
|
||||
selected = Some(matches.first().unwrap());
|
||||
|
||||
match matches.iter().enumerate().find(|&h| h.0 == state.skip) {
|
||||
Some(hm) => {
|
||||
choosen = hm.1;
|
||||
selected = Some(hm.1);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
exec_command(format!("tmux set-buffer {}", choosen.text));
|
||||
|
||||
break;
|
||||
}
|
||||
Key::Up => { state.prev(); }
|
||||
@ -167,19 +177,19 @@ fn main() {
|
||||
Key::Char(ch) => {
|
||||
let key = ch.to_string();
|
||||
let lower_key = key.to_lowercase();
|
||||
|
||||
typed_hint.push_str(lower_key.as_str());
|
||||
|
||||
match matches.iter().find(|mat| mat.hint == Some(typed_hint.clone())) {
|
||||
Some(mat) => {
|
||||
exec_command(format!("tmux set-buffer {}", mat.text));
|
||||
|
||||
if key != lower_key {
|
||||
paste = true;
|
||||
}
|
||||
selected = Some(mat);
|
||||
paste = key != lower_key;
|
||||
|
||||
break;
|
||||
},
|
||||
None => {
|
||||
if typed_hint.len() > longest_hint {
|
||||
if typed_hint.len() >= longest_hint {
|
||||
selected = None;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -194,7 +204,12 @@ fn main() {
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(mat) = selected {
|
||||
exec_command(str::replace(command, "{}", mat.text));
|
||||
|
||||
if paste {
|
||||
exec_command(format!("tmux paste-buffer"));
|
||||
exec_command(upcase_command.to_string());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user