diff --git a/README.md b/README.md index f871f42..7bed636 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,12 @@ bind-key F run-shell "flash_tmux" - Enter: paste and send Enter. - Space: paste and send Space. +### Options + +- `-r`, `--reverse-label`: Reverse label behavior. + - Lowercase: copy only. + - Uppercase: copy + paste. + ## Matching behavior - Only the visible pane content can be matched. diff --git a/src/config.rs b/src/config.rs index 3958bbe..8fa7a78 100644 --- a/src/config.rs +++ b/src/config.rs @@ -12,6 +12,7 @@ pub struct Config { pub prompt_indicator: String, pub label_characters: String, pub trimmable_chars: String, + pub reverse_label: bool, pub highlight_style: StyleSpec, pub current_style: StyleSpec, pub label_style: StyleSpec, @@ -27,6 +28,7 @@ impl Config { prompt_indicator: "❯".to_string(), label_characters: "jklhgfdsauiopytrewqnmvbcxz".to_string(), trimmable_chars: "()[]{}\"'`,.:;".to_string(), + reverse_label: false, highlight_style: StyleSpec::new(Some(Color::Rgb { r: 186, g: 187, diff --git a/src/main.rs b/src/main.rs index c3744ab..daa7388 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,9 +13,12 @@ struct Cli { interactive: bool, #[arg(long)] pane_id: Option, + /// Reverse label behavior: lowercase=copy only, uppercase=copy+paste + #[arg(short = 'r', long)] + reverse_label: bool, } -fn run_parent() -> Result<()> { +fn run_parent(cli: &Cli) -> Result<()> { let pane_id = tmux::get_tmux_pane_id()?; let in_copy_mode = tmux::is_in_copy_mode(&pane_id); let pane_content = tmux::capture_pane(&pane_id, in_copy_mode).unwrap_or_default(); @@ -46,6 +49,14 @@ fn run_parent() -> Result<()> { pane_id.clone(), ]; + let args = if cli.reverse_label { + let mut mut_args = args; + mut_args.push("-r".to_string()); + mut_args + } else { + args + }; + let status = Command::new("tmux").args(&args).status()?; let result_text = tmux::read_result_buffer(&pane_id) @@ -75,7 +86,8 @@ fn run_interactive(cli: &Cli) -> Result<()> { .pane_id .clone() .context("pane-id is required in interactive mode")?; - let config = Config::defaults(); + let mut config = Config::defaults(); + config.reverse_label = cli.reverse_label; let pane_content = tmux::read_pane_content_buffer(&pane_id) .ok() @@ -96,6 +108,6 @@ fn main() -> Result<()> { if cli.interactive { run_interactive(&cli) } else { - run_parent() + run_parent(&cli) } } diff --git a/src/ui.rs b/src/ui.rs index 9deac40..7f26f2d 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -108,9 +108,17 @@ impl<'a> InteractiveUI<'a> { self.search.get_match_by_label(label_lookup) { let action = if c.is_ascii_lowercase() { - ExitAction::Paste + if self.config.reverse_label { + ExitAction::CopyOnly + } else { + ExitAction::Paste + } } else { - ExitAction::CopyOnly + if self.config.reverse_label { + ExitAction::Paste + } else { + ExitAction::CopyOnly + } }; let text = trim_wrapping_token( match_item.text,