-
Notifications
You must be signed in to change notification settings - Fork 336
/
pattern-check
42 lines (33 loc) · 1.12 KB
/
pattern-check
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env bash
#
# Collection of various test strings that could be the output of the tmux
# 'pane_current_comamnd' message. Included as regression test for updates to
# the inline grep pattern used in the `.tmux.conf` configuration
set -e
RED=$(tput setaf 1)
GREEN=$(tput setaf 2)
YELLOW=$(tput setaf 3)
NORMAL=$(tput sgr0)
vim_pattern='(^|\/)g?(view|l?n?vim?x?|fzf)(diff)?$'
match_tests=(vim Vim VIM vimdiff lvim /usr/local/bin/vim vi gvim view gview nvim vimx fzf)
no_match_tests=( /Users/christoomey/.vim/thing /usr/local/bin/start-vim )
display_matches() {
for process_name in "$@"; do
printf "%s %s\n" "$(matches_vim_pattern $process_name)" "$process_name"
done
}
matches_vim_pattern() {
if echo "$1" | grep -iqE "$vim_pattern"; then
echo "${GREEN}match${NORMAL}"
else
echo "${RED}fail${NORMAL}"
fi
}
main() {
echo "Testing against pattern: ${YELLOW}$vim_pattern${NORMAL}\n"
echo "These should all ${GREEN}match${NORMAL}\n----------------------"
display_matches "${match_tests[@]}"
echo "\nThese should all ${RED}fail${NORMAL}\n---------------------"
display_matches "${no_match_tests[@]}"
}
main