Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add stored search for matching email addresses #78

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### master
- if installed use `gawk` instead of `awk` (@metcalfc)
- add stored search for matching git SHAs (@jbnicolai)
- add stored search for matching email addresses (@davidjb)

### v2.1.0, Jan 01, 2015
- combine send-keys calls to reduce flickering (@toupeira)
Expand Down
4 changes: 4 additions & 0 deletions copycat.tmux
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ set_default_stored_searches() {
local digit_search="$(get_tmux_option "$copycat_digit_search_option" "$default_digit_search_key")"
local hash_search="$(get_tmux_option "$copycat_hash_search_option" "$default_hash_search_key")"
local ip_search="$(get_tmux_option "$copycat_ip_search_option" "$default_ip_search_key")"
local email_search="$(get_tmux_option "$copycat_email_search_option" "$default_email_search_key")"

if stored_search_not_defined "$url_search"; then
tmux set-option -g "${COPYCAT_VAR_PREFIX}_${url_search}" "(https?://|git@|git://|ssh://|ftp://|file:///)[[:alnum:]?=%/_.:,;~@!#$&()*+-]*"
Expand All @@ -29,6 +30,9 @@ set_default_stored_searches() {
if stored_search_not_defined "$ip_search"; then
tmux set-option -g "${COPYCAT_VAR_PREFIX}_${ip_search}" "[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}"
fi
if stored_search_not_defined "$email_search"; then
tmux set-option -g "${COPYCAT_VAR_PREFIX}_${email_search}" '[[:alnum:].!#$%&*+/=?^_\`{|}~-]+@[[:alnum:]-]+(\.[[:alnum:]]+)*'
fi
}

set_start_bindings() {
Expand Down
3 changes: 3 additions & 0 deletions scripts/variables.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ copycat_hash_search_option="@copycat_hash_search"

default_ip_search_key="M-i"
copycat_ip_search_option="@copycat_ip_search"

default_email_search_key="C-e"
copycat_email_search_option="@copycat_email_search"
23 changes: 23 additions & 0 deletions test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,26 @@ Tests are written with the [expect tool](http://expect.sourceforge.net/).
From the `tmux copycat` project top directory run:

$ ./run-tests

### Debugging tests

In your tests, you can add a call to expect's interactive debugger with
``debug 1`` where you'd like to start debugging.

From the `tmux copycat` project top directory, bring up and access the given Vagrant VM:

$ vagrant up [ubuntu|centos]
$ vagrant ssh [ubuntu|centos]

and inside the VM, run the tests manually:

$ cd /vagrant
$ ./test/run-tests-within-vm

During this process, you can watch the progress of the tests interactively
by attaching yourself to the existing ``tmux`` server within the VM by
running ``tmux attach-session``. Note that there may be multiple sessions
and windows in use, depending on how many times your tests have run, so
check through each until you find the applicable one. Take care not to
disrupt the tests whilst running or you will encounter false results!

3 changes: 2 additions & 1 deletion test/helpers/expect_copycat_assertions.exp
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ proc _display_highlighted_with_checker_text {checker} {
_copy_mode_copy
send ""
sleep 0.1
send "echo $checker"
send "echo '$checker"
sleep 0.1
_tmux_paste
send "'"
send "\r"
}

Expand Down
5 changes: 5 additions & 0 deletions test/helpers/expect_copycat_helpers.exp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ proc tmux_ctrl_t {} {
sleep 0.7
}

proc tmux_ctrl_e {} {
send ""
sleep 0.7
}

proc search {text} {
send "/"
sleep 0.2
Expand Down
2 changes: 1 addition & 1 deletion test/helpers/expect_helpers.exp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ proc clear_screen {} {
}

proc display_text {text} {
send "echo $text\r"
send "echo '$text'\r"
sleep 0.1
}

Expand Down
155 changes: 155 additions & 0 deletions test/test_email_search.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
#!/usr/bin/env expect

source "./test/helpers/setup.exp"

# searches at the top of the pane
#--------------------------------
display_text "example@example1.com"
tmux_ctrl_e
assert_highlighted "example@example1.com" "top of the pane, email"

new_tmux_pane
display_text "example@example1.com.au"
tmux_ctrl_e
assert_highlighted "example@example1.com" "top of the pane, email country code"

# middle of pane searches
#------------------------
new_tmux_pane
create_output
clear_screen
display_text "example@example2.com"
tmux_ctrl_e
assert_highlighted "example@example2.com" "middle of the pane, email, beginning of the line"

display_text "random example@example3.com"
tmux_ctrl_e
assert_highlighted "example@example3.com" "middle of the pane, email, not beginning of the line"

display_text "example@example4.com"
tmux_ctrl_e
assert_highlighted "example@example4.com" "middle of the pane, email, beginning of the line"

display_text "some text example@example5.com"
tmux_ctrl_e
assert_highlighted "example@example5.com" "middle of the pane, email, not beginning of the line"

create_output
sleep 0.2
send " example@example6.com "
sleep 0.2
tmux_ctrl_e
assert_highlighted "example@example6.com" "middle of the pane, email, pane bottom"

# other email structures
#-----------------------
new_tmux_pane
create_output
clear_screen

display_text "example.person@example.com"
tmux_ctrl_e
assert_highlighted "example.person@example.com" "middle of the pane, dotted email"

display_text "example.person+subject@example.com"
tmux_ctrl_e
assert_highlighted "example.person+subject@example.com" "middle of the pane, dotted email with plus"

display_text "example@host.example.mueseum"
tmux_ctrl_e
assert_highlighted "example@host.example.mueseum" "middle of the pane, new gTLDs, .mueseum"

display_text "example@host.example.party"
tmux_ctrl_e
assert_highlighted "example@host.example.party" "middle of the pane, new gTLDs, .party"

display_text "example.\!\#\$%&*+/=?^_`\{|\}~-@example-one.com"
tmux_ctrl_e
assert_highlighted "example.\!\#\$%&*+/=?^_`\{|\}~-@example-one.com" "middle of the pane, all special characters"

# emails in html
#---------------
new_tmux_pane
display_text "<a href='mailto:example@example61.com?subject=Test'>asdf</a>"
tmux_ctrl_e
assert_highlighted "example@example61.com" "email, subject in html"

# match selection when line contains escaped chars
#-------------------------------------------------
new_tmux_pane
display_text "User ID: example\r\nEmail: example@example7.com\r\n"
tmux_ctrl_e
assert_highlighted "example@example7.com" "match selection when line contains escaped chars"

# result navigation
#------------------
new_tmux_pane
display_text "example@example81.com"
display_text "example@example82.com"
display_text "example@example83.com"
tmux_ctrl_e
# example@example83.com
next_match
# example@example83.com
next_match
# example@example82.com
next_match
# example@example82.com
next_match
# example@example81.com
previous_match
# example@example82.com
assert_highlighted "example@example82.com" "result navigation at the top of the pane"

create_output
display_text "example@example91.com"
display_text "example@example92.com"
tmux_ctrl_e
# example@example92.com
next_match
# example@example92.com
next_match
# example@example91.com
previous_match
# example@example92.com
assert_highlighted "example@example92.com" "result navigation, middle of the pane"

# 2 matches on the same line
#---------------------------
new_tmux_pane
display_text "example@example101.com example@example102.com"
tmux_ctrl_e
assert_highlighted "example@example101.com" "2 matches on the same line, first match"

display_text "example@example111.com example@example112.com"
tmux_ctrl_e
next_match
assert_highlighted "example@example112.com" "2 matches on the same line, second match"

# no match, first and last match
#-------------------------------
new_tmux_pane
tmux_ctrl_e
assert_on_screen "No results!" "No results is displayed when no results"

display_text "example@example12.com"
tmux_ctrl_e
next_match
next_match
assert_on_screen "Last match!" "'Last match' is displayed when last match"
# exit copycat mode
send ""

new_tmux_pane
display_text "example@example13.com"
tmux_ctrl_e
next_match
previous_match
previous_match
assert_on_screen "First match!" "'First match' is displayed when first match"
# exit copycat mode
send ""

# quit
#-----
teardown_and_exit
4 changes: 2 additions & 2 deletions test/test_file_search.exp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ next_match
# /file/1.txt
previous_match
# /file/2.txt
assert_highlighted " /file/2.txt" "result navigation at the top of the pane"
assert_highlighted "/file/2.txt" "result navigation at the top of the pane"

create_output
display_text "/file/1.txt"
Expand All @@ -79,7 +79,7 @@ next_match
# /file/1.txt
previous_match
# /file/2.txt
assert_highlighted " /file/2.txt" "result navigation, middle of the pane"
assert_highlighted "/file/2.txt" "result navigation, middle of the pane"

# 2 matches on the same line
#---------------------------
Expand Down