-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgrep.sh
More file actions
60 lines (56 loc) · 1.43 KB
/
grep.sh
File metadata and controls
60 lines (56 loc) · 1.43 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/zsh
cwd=$0:A:h
source "$cwd/find.sh"
source "$cwd/conf.sh"
_grepLangGrep () {
grep --color=auto -nH "$@"
}
_grepLangInit () {
_grepLangSearchPATH=( "$@" )
}
# TODO: move to find.sh
_grepFindFilesToGrep_find () {
local IFS=$'\n'
local findargs=(
-type f
-not -wholename '*/.stversions/*'
-not -wholename '*/docker-data/*'
-not -wholename '*/node_modules/*'
)
local langfiles=($(find $_grepLangSearchPATH -regex ".*/$__brain_suffix"'[^/]*[^~]$\|.*'"$__brain_suffix$" $findargs))
local todos=($(find $_grepLangSearchPATH -name "todo" -type f))
for t in $todos; do langfiles+=$t; done
echo "${langfiles[@]}"
}
_grepFindFilesToGrep_fd () {
local opts=($(printf ' -E "%s" ' "${__brain_directory_ignores[@]}"))
local f=($(fd $opts "(^$__brain_suffix\.|\.$__brain_suffix$)" $_grepLangSearchPATH))
if [[ $#f -eq 0 ]]; then
f=($(fd $opts "(^${__brain_suffix}\.[^/]*|[^/]*\.${__brain_suffix})" $_grepLangSearchPATH))
fi
echo "${f}"
}
_grepFindFilesToGrep () {
if which fd >/dev/null; then
_grepFindFilesToGrep_fd
else
_grepFindFilesToGrep_find
fi
}
_grepLangAndTodoFiles () {
_grepLangGrep "$@" $(_grepFindFilesToGrep)
}
grepz () {
_grepLangInit $__brain_roots[2]
_grepLangAndTodoFiles "$@";
}
alias grepstu=grepz
grep0x () {
_grepLangInit $__brain_roots[1]
_grepLangAndTodoFiles "$@"
}
greplang () {
_grepLangInit $__brain_roots
_grepLangAndTodoFiles "$@"
}
alias grepbrain='greplang'