Skip to content

Commit be123ba

Browse files
author
Francisco Lopes
committed
Adopt grep -P to improve matches
- Fix support for matching quotes in URLs - Don't match whitespace before file paths - grep -P is needed
1 parent e95528e commit be123ba

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

copycat.tmux

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ set_default_stored_searches() {
1515
local ip_search="$(get_tmux_option "$copycat_ip_search_option" "$default_ip_search_key")"
1616

1717
if stored_search_not_defined "$url_search"; then
18-
tmux set-option -g "${COPYCAT_VAR_PREFIX}_${url_search}" "(https?://|git@|git://|ssh://|ftp://|file:///)[[:alnum:]?=%/_.:,;~@!#$&()*+-]*"
18+
tmux set-option -g "${COPYCAT_VAR_PREFIX}_${url_search}" "(https?://|git@|git://|ssh://|ftp://|file:///)[\x22\x27[:alnum:]?=%/_.:,;~@!#$&()*+-]*"
1919
fi
2020
if stored_search_not_defined "$file_search"; then
21-
tmux set-option -g "${COPYCAT_VAR_PREFIX}_${file_search}" "(^|^\.|[[:space:]]|[[:space:]]\.|[[:space:]]\.\.|^\.\.)[[:alnum:]~_-]*/[][[:alnum:]_.#$%&+=/@-]*"
21+
tmux set-option -g "${COPYCAT_VAR_PREFIX}_${file_search}" "(^|(?<=[[:space:]]))(\.|\.\.)?[[:alnum:]~_-]*/[][[:alnum:]_.#$%&+=/@-]*"
2222
fi
2323
if stored_search_not_defined "$digit_search"; then
2424
tmux set-option -g "${COPYCAT_VAR_PREFIX}_${digit_search}" "[[:digit:]]+"

scripts/copycat_generate_results.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ reverse_and_create_copycat_file() {
1717
local file=$1
1818
local copycat_file=$2
1919
local grep_pattern=$3
20-
(tac 2>/dev/null || tail -r) < "$file" | grep -oniE "$grep_pattern" > "$copycat_file"
20+
(tac 2>/dev/null || tail -r) < "$file" | grep -oniP "$grep_pattern" > "$copycat_file"
2121
}
2222

2323
delete_old_files() {

test/test_file_search.exp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,29 +25,29 @@ assert_highlighted "/this/is/some/file.txt" "middle of the pane, absolute path,
2525

2626
display_text "random /this/is/some/file.txt"
2727
tmux_ctrl_f
28-
assert_highlighted " /this/is/some/file.txt" "middle of the pane, absolute path, not beginning of the line"
28+
assert_highlighted "/this/is/some/file.txt" "middle of the pane, absolute path, not beginning of the line"
2929

3030
display_text "another/file.txt"
3131
tmux_ctrl_f
3232
assert_highlighted "another/file.txt" "middle of the pane, relative path, beginning of the line"
3333

3434
display_text "some text another/file.txt"
3535
tmux_ctrl_f
36-
assert_highlighted " another/file.txt" "middle of the pane, relative path, not beginning of the line"
36+
assert_highlighted "another/file.txt" "middle of the pane, relative path, not beginning of the line"
3737

3838
create_output
3939
sleep 0.2
4040
send " some/file.xyz "
4141
sleep 0.2
4242
tmux_ctrl_f
43-
assert_highlighted " some/file.xyz" "middle of the pane relative path, pane bottom"
43+
assert_highlighted "some/file.xyz" "middle of the pane relative path, pane bottom"
4444

4545
# match selection when line contains escaped chars
4646
#-------------------------------------------------
4747
new_tmux_pane
4848
display_text "filename=test.csv\r\nContent-Type: text/csv\r\n"
4949
tmux_ctrl_f
50-
assert_highlighted " text/csv" "match selection when line contains escaped chars"
50+
assert_highlighted "text/csv" "match selection when line contains escaped chars"
5151

5252
# result navigation
5353
#------------------
@@ -67,7 +67,7 @@ next_match
6767
# /file/1.txt
6868
previous_match
6969
# /file/2.txt
70-
assert_highlighted " /file/2.txt" "result navigation at the top of the pane"
70+
assert_highlighted "/file/2.txt" "result navigation at the top of the pane"
7171

7272
create_output
7373
display_text "/file/1.txt"
@@ -80,7 +80,7 @@ next_match
8080
# /file/1.txt
8181
previous_match
8282
# /file/2.txt
83-
assert_highlighted " /file/2.txt" "result navigation, middle of the pane"
83+
assert_highlighted "/file/2.txt" "result navigation, middle of the pane"
8484

8585
# 2 matches on the same line
8686
#---------------------------
@@ -92,7 +92,7 @@ assert_highlighted "/file/1.txt" "2 matches on the same line, first match"
9292
display_text "/file/1.txt another/file/2.txt"
9393
tmux_ctrl_f
9494
next_match
95-
assert_highlighted " another/file/2.txt" "2 matches on the same line, second match"
95+
assert_highlighted "another/file/2.txt" "2 matches on the same line, second match"
9696

9797
# no match, first and last match
9898
#-------------------------------
@@ -130,15 +130,15 @@ exit_irb
130130
enter_irb
131131
irb_display_text "some text file/within/irb.rb"
132132
tmux_ctrl_f
133-
irb_assert_highlighted " file/within/irb.rb" "irb console relative path, not beggining of line"
133+
irb_assert_highlighted "file/within/irb.rb" "irb console relative path, not beggining of line"
134134
exit_irb
135135

136136
enter_irb
137137
irb_generate_output
138138
send "puts /absolute/file/irb.rb"
139139
sleep 5
140140
tmux_ctrl_f
141-
irb_assert_highlighted " /absolute/file/irb.rb" "irb console absolute path, pane bottom, not beggining of line"
141+
irb_assert_highlighted "/absolute/file/irb.rb" "irb console absolute path, pane bottom, not beggining of line"
142142
exit_irb
143143

144144
# quit

0 commit comments

Comments
 (0)