tmux-copycat icon indicating copy to clipboard operation
tmux-copycat copied to clipboard

If a group is defined in the regexp, only highlight/copy this group

Open AnAppAMonth opened this issue 10 years ago • 3 comments

This way we can choose to only copy part of the match. Sometimes we provide context for matching but don't want to copy it (and it seems like lookahead and lookback aren't supported).

A less intrusive option is if there is a specific named group then only highlight/copy that.

AnAppAMonth avatar Mar 19 '15 15:03 AnAppAMonth

I agree this would be very nice and it would enable some nice things we can't have because these other features are missing.

If this can be implemented in a non-complex way, I'd be very open to accepting a PR.

bruno- avatar Apr 02 '15 14:04 bruno-

I made a slight change to use perl regex (-P) instead of Extended regex (-E) # (tac 2>/dev/null || tail -r) < "$file" | grep -oniE "$grep_pattern" > "$copycat_file" (tac 2>/dev/null || tail -r) < "$file" | grep -oniP "$grep_pattern" > "$copycat_file"

This allowed me to to some lookahead/lookback in my .tmux.conf

Match everything on a line following prompt> but do not include prompt>

set -g @copycat_search_C-i '(?<=prompt> ).*'

Match object names between { } but do not include { }

set -g @copycat_search_C-o "(?<={)[a-zA-Z0-9_/.-]+(?=})"

Details on the Perl Look Ahead Assertions that I used (?<=) and (?=) are here: http://perldoc.perl.org/perlre.html#Extended-Patterns

croysdale avatar Oct 16 '15 17:10 croysdale

Hey, that's nice. Just keep in mind grep -P flag is not part of posix definition. For example, it wouldn't work on OSX.

bruno- avatar Oct 25 '15 14:10 bruno-