Merge pull request #18 from fcsonline/feature/fix-command

Fix command and paste command arguments
This commit is contained in:
Ferran Basora 2019-12-05 19:35:14 +01:00 committed by GitHub
commit 2c069a21ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 16 deletions

View File

@ -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 {}'`
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:
```
set -g @thumbs-command 'pbcopy'
set -g @thumbs-command 'echo {} | pbcopy'
```
### @thumbs-upcase-command
`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:
```
set -g @thumbs-upcase-command 'pbcopy'
set -g @thumbs-upcase-command 'echo {} | pbcopy'
```
### @thumbs-bg-color

View File

@ -10,9 +10,7 @@ use self::clap::{App, Arg};
use clap::crate_version;
use std::process::Command;
fn exec_command(command: String) -> std::process::Output {
let args: Vec<_> = command.split(" ").collect();
fn exec_command(args: Vec<&str>) -> std::process::Output {
return Command::new(args[0])
.args(&args[1..])
.output()
@ -136,13 +134,14 @@ fn main() {
let command = args.value_of("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 lines = output.split("\n").collect::<Vec<&str>>();
@ -166,14 +165,22 @@ fn main() {
};
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 {
exec_command(str::replace(command, "{}", text.as_str()));
exec_command(vec![
"bash",
"-c",
str::replace(command, "{}", text.as_str()).as_str(),
]);
if paste {
exec_command(upcase_command.to_string());
exec_command(vec![
"bash",
"-c",
str::replace(upcase_command, "{}", text.as_str()).as_str(),
]);
}
}
}