-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch
executable file
·56 lines (47 loc) · 1.85 KB
/
search
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
#!/bin/bash
# Keyword Finder - Search keyword inside the files.
# Copyright (C) 1995-2023 Richard Huang <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
: ${SEARCH_IGNORE_FILE:=.searchignore}
function usage {
echo -e "Usage: $0 [-e <exclude folder> ...] -h <keyword> -s\n"
echo "Command line switches are optional. The following switches are recognized."
echo " -e -- Folder to be excluded from the search path."
echo " -h -- Show this usage."
echo " -s -- Skip .searchignore file."
exit 1
}
while getopts ":e:hs" o; do
case "$o" in
e) EXCLUDES+=("$OPTARG");;
h) usage;;
s) SKIP_IGNORE=true;;
esac
done
shift $((OPTIND-1))
FIND_ARGS+="-not \( -path '*.git/*' -prune \)"
if [ "$SKIP_IGNORE" != true ]; then
if [ -f $SEARCH_IGNORE_FILE ]; then
while read EXCLUDE; do
FIND_ARGS+=" -not \( -path '*$EXCLUDE*' -prune \)"
done < $SEARCH_IGNORE_FILE
fi
fi
if [ ! -z "$EXCLUDES" ]; then
for EXCLUDE in "${EXCLUDES[@]}"; do
FIND_ARGS+=" -not \( -path '*$EXCLUDE*' -prune \)"
done
fi
eval "find . -type f $FIND_ARGS -print0 2>/dev/null" | xargs -0 grep --color=always --line-buffered -HIinrs "$1"