From fde1a676e70cc24620987bca01d0348d87504510 Mon Sep 17 00:00:00 2001 From: Alpha Chen Date: Mon, 8 Apr 2024 20:25:37 -0700 Subject: [PATCH] ,tmux-copy --- .tmux.conf | 3 ++- bin/,tmux-copy | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100755 bin/,tmux-copy diff --git a/.tmux.conf b/.tmux.conf index 873a161..104dd19 100644 --- a/.tmux.conf +++ b/.tmux.conf @@ -100,7 +100,8 @@ bind -r - resize-pane -D 3 bind -r + resize-pane -U 3 bind -r = resize-pane -U 3 -unbind r +bind C-y run-shell -b ~/.dotfiles/bin/,tmux-copy + bind r source-file ~/.tmux.conf \; display 'Reloaded tmux.conf' if-shell "[[ -e ~/.tmux.conf.local ]]" "source-file ~/.tmux.conf.local" diff --git a/bin/,tmux-copy b/bin/,tmux-copy new file mode 100755 index 0000000..6d16622 --- /dev/null +++ b/bin/,tmux-copy @@ -0,0 +1,20 @@ +#!/usr/bin/env zsh + +set -euo pipefail + +TMPFILE=$(mktemp) +RG_OPTS="--word-regexp" +PATTERNS=( + "[a-f0-9]{5,}" # hex, assuming only want to copy 5+ characters + "[^\\s]+" +) +PATTERN=${(j[|])PATTERNS} + +tmux capture-pane -p -S -2 > "$TMPFILE" + +rg "$RG_OPTS" --ignore-case --only-matching "$PATTERN" "$TMPFILE" | + ruby -e 'ARGF.readlines(chomp: true).uniq.each { puts _1 }' | + fzf-tmux -p 80%,60% --layout=reverse \ + --print0 \ + --preview "rg $RG_OPTS --color=always --context=3 {} $TMPFILE" \ + --bind "enter:execute-silent(pbcopy <<< {})+abort" || true