Add support for more paths
dblume

dblume commited on 2025-11-15 11:12:48
Showing 1 changed files, with 1 additions and 1 deletions.


Decided I wanted to allow paths with two separators, even if no linenum.
Ending with a linenum is always a match. So now matches are:
* file:23
* ~/path/filename
* /path/filename
* path/path/filename

The more obvious ones still match, of course:

* path/file:23:45
* "~/path with spaces/file":23:45

We intentionally do not match single separators

* (No match) path/filename

If we allowed that, the regex could be shorter, so there's that.
... ...
@@ -42,7 +42,7 @@ bind -n M-l select-pane -R
42 42
 # 2. Prefix + f to enter copy mode and search backward for a file path regex.
43 43
 # 3. Once found, Prefix + o to open the file in $EDITOR.
44 44
 bind-key f copy-mode \; send-keys -X search-backward \
45
-  '(^|\<|[[:space:]/])("[/]?[[:alnum:] _\.#$%&+=@-]+(/[[:alnum:] _\.#$%&+=@-]+)*"|[[:alnum:]_\.#$%&+=@-]+(/[[:alnum:]_\.#$%&+=@-]+)*[[:alnum:]_\.#$%&+=@-]+):[0-9]{1,10}(:[0-9]{1,10})?'
45
+  '(^|\<|[[:space:]/])(("(~/|/)?[[:alnum:] _\.#$%&+=@-]+(/[[:alnum:] _\.#$%&+=@-]+)*"|(~/|/)?[[:alnum:]_\.#$%&+=@-]+(/[[:alnum:]_\.#$%&+=@-]+)*[[:alnum:]_\.#$%&+=@-]+):[0-9]{1,10}(:[0-9]{1,10})?)|~?/[[:alnum:]_\.#$%&+=@-]+(/[[:alnum:]_\.#$%&+=@-]+)+|[[:alnum:]_\.#$%&+=@-]+(/[[:alnum:]_\.#$%&+=@-]+){2,}'
46 46
 
47 47
 # save the buffer, then open an editor in the current pane
48 48
 bind-key -T copy-mode-vi o send-keys -X copy-pipe-and-cancel \
49 49