Skip to content

Commit 279db60

Browse files
Joshua AppelmanBruno Sutic
authored andcommitted
Adds M-h predefined SHA1 hash search.
1 parent 55640d1 commit 279db60

File tree

6 files changed

+47
-0
lines changed

6 files changed

+47
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Searches are case insensitive.<br/>
3737

3838
- `prefix + ctrl-f` - simple *f*ile search
3939
- `prefix + ctrl-g` - jumping over *g*it status files (best used after `git status` command)
40+
- `prefix + alt-h` - jumping over SHA-1 hashes (best used after `git log` command)
4041
- `prefix + ctrl-u` - *u*rl search (http, ftp and git urls)
4142
- `prefix + ctrl-d` - number search (mnemonic d, as digit)
4243
- `prefix + alt-i` - *i*p address search

copycat.tmux

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ set_default_stored_searches() {
1111
local file_search="$(get_tmux_option "$copycat_file_search_option" "$default_file_search_key")"
1212
local url_search="$(get_tmux_option "$copycat_url_search_option" "$default_url_search_key")"
1313
local digit_search="$(get_tmux_option "$copycat_digit_search_option" "$default_digit_search_key")"
14+
local hash_search="$(get_tmux_option "$copycat_hash_search_option" "$default_hash_search_key")"
1415
local ip_search="$(get_tmux_option "$copycat_ip_search_option" "$default_ip_search_key")"
1516

1617
if stored_search_not_defined "$url_search"; then
@@ -22,6 +23,9 @@ set_default_stored_searches() {
2223
if stored_search_not_defined "$digit_search"; then
2324
tmux set-option -g "${COPYCAT_VAR_PREFIX}_${digit_search}" "[[:digit:]]+"
2425
fi
26+
if stored_search_not_defined "$hash_search"; then
27+
tmux set-option -g "${COPYCAT_VAR_PREFIX}_${hash_search}" "\b[0-9a-f]{7,40}\b"
28+
fi
2529
if stored_search_not_defined "$ip_search"; then
2630
tmux set-option -g "${COPYCAT_VAR_PREFIX}_${ip_search}" "[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}"
2731
fi

scripts/variables.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,8 @@ copycat_url_search_option="@copycat_url_search"
1919
default_digit_search_key="C-d"
2020
copycat_digit_search_option="@copycat_digit_search"
2121

22+
default_hash_search_key="M-h"
23+
copycat_hash_search_option="@copycat_hash_search"
24+
2225
default_ip_search_key="M-i"
2326
copycat_ip_search_option="@copycat_ip_search"

test/helpers/expect_copycat_helpers.exp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ proc tmux_ctrl_g {} {
2525
sleep 0.7
2626
}
2727

28+
proc tmux_ctrl_h {} {
29+
send ""
30+
sleep 0.7
31+
}
32+
2833
proc tmux_ctrl_t {} {
2934
send ""
3035
sleep 0.7

test/helpers/expect_helpers.exp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,18 @@ proc git_status {} {
8181
sleep 0.1
8282
}
8383

84+
proc git_log_reverse_short {} {
85+
sleep 0.1
86+
send "git --no-pager log --reverse --oneline -1\r"
87+
sleep 0.1
88+
}
89+
90+
proc git_log_reverse {} {
91+
sleep 0.1
92+
send "git --no-pager log --reverse -1\r"
93+
sleep 0.1
94+
}
95+
8496
proc git_checkout {} {
8597
sleep 0.1
8698
send "git checkout -- .\r"

test/test_git_hash_search.exp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env expect
2+
3+
source "./test/helpers/setup.exp"
4+
5+
enter_test_git_repo
6+
7+
# Match regular SHA-1 hashes
8+
#---------------------------
9+
git_log_reverse
10+
tmux_ctrl_g
11+
assert_highlighted "29a71f6749a5413f42445372052e612e937b23d6" "match regular SHA-1 hashes"
12+
13+
#Match shortened SHA-1 hashes
14+
#----------------------------
15+
git_log_reverse_short
16+
tmux_ctrl_g
17+
assert_highlighted "29a71f6" "match shortened SHA-1 hashes"
18+
19+
# quit
20+
#-----
21+
remove_test_git_repo
22+
teardown_and_exit

0 commit comments

Comments
 (0)