From f15f02c26bb77b134dec6a08f1a6a8c5508786e6 Mon Sep 17 00:00:00 2001 From: Ferran Basora Date: Sun, 8 Dec 2019 12:02:58 +0100 Subject: [PATCH] Exclusive commands Before this commit `command` and `upcase_command` where executed if you pressed an uppercase key. This can force the user to have a innocuous lower case command if they want to execute together. Now they can be totally independent. --- README.md | 2 +- src/main.rs | 22 ++++++++-------------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 0d98742..4df9271 100644 --- a/README.md +++ b/README.md @@ -166,7 +166,7 @@ set -g @thumbs-command 'echo {} | pbcopy' ### @thumbs-upcase-command -`default: 'tmux paste-buffer'` +`default: 'tmux set-buffer {} && tmux paste-buffer'` Choose which command execute when you press a upcase hint. `tmux-thumbs` will replace `{}` with the picked hint. diff --git a/src/main.rs b/src/main.rs index 6439b4b..1e55510 100644 --- a/src/main.rs +++ b/src/main.rs @@ -93,7 +93,7 @@ fn app_args<'a>() -> clap::ArgMatches<'a> { Arg::with_name("upcase_command") .help("Upcase command") .long("upcase-command") - .default_value("tmux paste-buffer"), + .default_value("tmux set-buffer {} && tmux paste-buffer"), ) .arg( Arg::with_name("regexp") @@ -168,19 +168,13 @@ fn main() { exec_command(vec!["tmux", "swap-pane", "-t", pane]); }; - if let Some((text, paste)) = selected { - exec_command(vec![ - "bash", - "-c", - str::replace(command, "{}", text.as_str()).as_str(), - ]); + if let Some((text, upcase)) = selected { + let final_command = if upcase { + str::replace(upcase_command, "{}", text.as_str()) + } else { + str::replace(command, "{}", text.as_str()) + }; - if paste { - exec_command(vec![ - "bash", - "-c", - str::replace(upcase_command, "{}", text.as_str()).as_str(), - ]); - } + exec_command(vec!["bash", "-c", final_command.as_str()]); } }