mirror of
https://github.com/FliegendeWurst/tmux-thumbs.git
synced 2024-11-22 21:05:00 +00:00
Fix command and paste command arguments
Improve flexibility in `command` and `upcase-command` replacing `{}` with the selected hint.
This commit is contained in:
parent
d6c91815e7
commit
fb7e6da20a
@ -156,24 +156,24 @@ set @thumbs-regexp-2 '[a-f0-9]{2}:[a-f0-9]{2}:[a-f0-9]{2}:[a-f0-9]{2}:[a-f0-9]{2
|
|||||||
|
|
||||||
`default: 'tmux set-buffer {}'`
|
`default: 'tmux set-buffer {}'`
|
||||||
|
|
||||||
Choose which command execute when you press a hint.
|
Choose which command execute when you press a hint. `tmux-thumbs` will replace `{}` with the picked hint.
|
||||||
|
|
||||||
For example:
|
For example:
|
||||||
|
|
||||||
```
|
```
|
||||||
set -g @thumbs-command 'pbcopy'
|
set -g @thumbs-command 'echo {} | pbcopy'
|
||||||
```
|
```
|
||||||
|
|
||||||
### @thumbs-upcase-command
|
### @thumbs-upcase-command
|
||||||
|
|
||||||
`default: 'tmux paste-buffer'`
|
`default: 'tmux paste-buffer'`
|
||||||
|
|
||||||
Choose which command execute when you press a upcase hint
|
Choose which command execute when you press a upcase hint. `tmux-thumbs` will replace `{}` with the picked hint.
|
||||||
|
|
||||||
For example:
|
For example:
|
||||||
|
|
||||||
```
|
```
|
||||||
set -g @thumbs-upcase-command 'pbcopy'
|
set -g @thumbs-upcase-command 'echo {} | pbcopy'
|
||||||
```
|
```
|
||||||
|
|
||||||
### @thumbs-bg-color
|
### @thumbs-bg-color
|
||||||
|
31
src/main.rs
31
src/main.rs
@ -10,9 +10,7 @@ use self::clap::{App, Arg};
|
|||||||
use clap::crate_version;
|
use clap::crate_version;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
fn exec_command(command: String) -> std::process::Output {
|
fn exec_command(args: Vec<&str>) -> std::process::Output {
|
||||||
let args: Vec<_> = command.split(" ").collect();
|
|
||||||
|
|
||||||
return Command::new(args[0])
|
return Command::new(args[0])
|
||||||
.args(&args[1..])
|
.args(&args[1..])
|
||||||
.output()
|
.output()
|
||||||
@ -136,13 +134,14 @@ fn main() {
|
|||||||
|
|
||||||
let command = args.value_of("command").unwrap();
|
let command = args.value_of("command").unwrap();
|
||||||
let upcase_command = args.value_of("upcase_command").unwrap();
|
let upcase_command = args.value_of("upcase_command").unwrap();
|
||||||
let tmux_subcommand = if let Some(pane) = args.value_of("tmux_pane") {
|
|
||||||
format!(" -t {}", pane)
|
|
||||||
} else {
|
|
||||||
"".to_string()
|
|
||||||
};
|
|
||||||
|
|
||||||
let execution = exec_command(format!("tmux capture-pane -e -J -p{}", tmux_subcommand));
|
let mut capture_command = vec!["tmux", "capture-pane", "-e", "-J", "-p"];
|
||||||
|
|
||||||
|
if let Some(pane) = args.value_of("tmux_pane") {
|
||||||
|
capture_command.extend(vec!["-t", pane].iter().cloned());
|
||||||
|
}
|
||||||
|
|
||||||
|
let execution = exec_command(capture_command);
|
||||||
let output = String::from_utf8_lossy(&execution.stdout);
|
let output = String::from_utf8_lossy(&execution.stdout);
|
||||||
let lines = output.split("\n").collect::<Vec<&str>>();
|
let lines = output.split("\n").collect::<Vec<&str>>();
|
||||||
|
|
||||||
@ -166,14 +165,22 @@ fn main() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if let Some(pane) = args.value_of("tmux_pane") {
|
if let Some(pane) = args.value_of("tmux_pane") {
|
||||||
exec_command(format!("tmux swap-pane -t {}", pane));
|
exec_command(vec!["tmux", "swap-pane", "-t", pane]);
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some((text, paste)) = selected {
|
if let Some((text, paste)) = selected {
|
||||||
exec_command(str::replace(command, "{}", text.as_str()));
|
exec_command(vec![
|
||||||
|
"bash",
|
||||||
|
"-c",
|
||||||
|
str::replace(command, "{}", text.as_str()).as_str(),
|
||||||
|
]);
|
||||||
|
|
||||||
if paste {
|
if paste {
|
||||||
exec_command(upcase_command.to_string());
|
exec_command(vec![
|
||||||
|
"bash",
|
||||||
|
"-c",
|
||||||
|
str::replace(upcase_command, "{}", text.as_str()).as_str(),
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user