Morantron / tmux-fingers

copy pasting in terminal with vimium/vimperator like hints.
MIT License
1k stars 46 forks source link

Issue with `\b` in a `@fingers-pattern-0` pattern #96

Closed ilyagr closed 1 year ago

ilyagr commented 1 year ago

I'd like to capture hashes from the output of a VCS I use. So, I put the following in my tmux.conf:

set -g @fingers-pattern-0 '\b([k-z]{5,}|[K-Z]{5,}|[0-9a-f]{5,})\b'
run-shell ~/.config/tmux/plugins/tmux-fingers/tmux-fingers.tmux

However, it doesn't work as I expect. Let's say I have the following text in my terminal (sorry, the example is a bit messy, this was after some grep-ing):

   ╷ │ │ │ │   │  Add mouse support for selecting and opening files (#963)
   ╷ │ │ ◉ │   │  SLMXST ilyagr@ 2022-10-16 12:21 -07 e5e1f1
   ◉ │ │   │   │  LRKVPX ilyagr@ 2022-10-16 18:54 +03 624992
   ◉ │ │       │  TRTVMR gokcehankara@ 2022-10-15 21:34 +03 654b87
   ◉   │       │  UMKQLL oue.paul18@ 2022-10-01 16:39 +03 4968b1
   ◉   │  KXXOXO oue.paul18@ 2022-09-08 16:10 +03 17e1a8

If I turn on fingers-mode, the strings e5e1f1 and SLMXST are not highlighted. Instead, '2022' is:

image

Meanwhile, grep works correctly (the fact that 'support' is highlighted is undesired, but it correctly matches the regex; the first line of the output is from my shell prompt): image

After a bit of thought, ~I think a likely explanation is that the unicode symbols mess up the counts somewhere inside tmux-fingers.sh~ (update: no, it's something config-related. Just the string SLMXST ilyagr@ 2022-10-16 12:21 -07 e5e1f1 behaves the same). In any case, help is appreciated.

I am using the latest version of tmux-fingers (commit 2e08de2) on Debian stable (bookworm) Linux.

ilyagr commented 1 year ago

Here's another piece of debug info. I'm not sure whether the '\b' at the end needs to be '\b' or not.

🐟 tmux showenv -g FINGERS_PATTERNS
FINGERS_PATTERNS=((^|^\.|[[:space:]]|[[:space:]]\.|[[:space:]]\.\.|^\.\.)[[:alnum:]~_-]*/[][[:alnum:]_.#$%&+=/@-]+)|([[:digit:]]{4,})|([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})|([0-9a-f]{7,128})|((https?://|git@|git://|ssh://|ftp://|file:///)[[:alnum:]?=%/_.:,;~@!#$&()*+-]*)|([[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3})|(0x[0-9a-fA-F]+)|(deployment.app|binding|componentstatuse|configmap|endpoint|event|limitrange|namespace|node|persistentvolumeclaim|persistentvolume|pod|podtemplate|replicationcontroller|resourcequota|secret|serviceaccount|service|mutatingwebhookconfiguration.admissionregistration.k8s.io|validatingwebhookconfiguration.admissionregistration.k8s.io|customresourcedefinition.apiextension.k8s.io|apiservice.apiregistration.k8s.io|controllerrevision.apps|daemonset.apps|deployment.apps|replicaset.apps|statefulset.apps|tokenreview.authentication.k8s.io|localsubjectaccessreview.authorization.k8s.io|selfsubjectaccessreviews.authorization.k8s.io|selfsubjectrulesreview.authorization.k8s.io|subjectaccessreview.authorization.k8s.io|horizontalpodautoscaler.autoscaling|cronjob.batch|job.batch|certificatesigningrequest.certificates.k8s.io|events.events.k8s.io|daemonset.extensions|deployment.extensions|ingress.extensions|networkpolicies.extensions|podsecuritypolicies.extensions|replicaset.extensions|networkpolicie.networking.k8s.io|poddisruptionbudget.policy|clusterrolebinding.rbac.authorization.k8s.io|clusterrole.rbac.authorization.k8s.io|rolebinding.rbac.authorization.k8s.io|role.rbac.authorization.k8s.io|storageclasse.storage.k8s.io)[[:alnum:]_#$%&+=/@-]+|\b([k-z]{5,}|[K-Z]{5,}|[0-9a-f]{5,})\b|\b([k-z]{5,}|[K-Z]{5,}|[0-9a-f]{5,})\b

This is kind of hard to read, but the end of the line is

\b([k-z]{5,}|[K-Z]{5,}|[0-9a-f]{5,})\b|\b([k-z]{5,}|[K-Z]{5,}|[0-9a-f]{5,})\b

I'm not sure why it's repeated twice.

ilyagr commented 1 year ago

I've figured out the problem. Turns out, tmux-fingers uses gawk regular expressions as opposed to grep -E regular expressions. While both are called "Extended Regular Expressions", they are different. In gawk, \b means backspace and \< & \> are word boundaries. In grep -E, \b is a word boundary while \< and > also work.

TIL. I'll file a PR for the documentation bug part of it.

TLDR: the following works

set -g @fingers-pattern-0 '\<([k-z]{5,}|[K-Z]{5,}|[0-9a-f]{5,})\>'