Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
18 changes: 15 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ struct Cli {
interactive: bool,
#[arg(long)]
pane_id: Option<String>,
/// 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();
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand All @@ -96,6 +108,6 @@ fn main() -> Result<()> {
if cli.interactive {
run_interactive(&cli)
} else {
run_parent()
run_parent(&cli)
}
}
12 changes: 10 additions & 2 deletions src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down