Repository navigation
Expand file tree
/
Copy pathffind
More file actions
executable file
·93 lines (82 loc) · 2.19 KB
/
Copy pathffind
File metadata and controls
executable file
·93 lines (82 loc) · 2.19 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/env sh
# (filtering find) - A wrapper around find to ignore noise directories
NAME=$(basename "$0")
VERSION='0.9.0'
help () {
# Extract contiguous lines of comments in a function as help text
awk -v cmd="${1:?'Command name required.'}" -v NAME="$NAME" '
$0 ~ "^" cmd "\\s*\\(\\)\\s*{" { is_found=1; next }
is_found && !NF { exit }
is_found { gsub(/^\s*#\s?/, ""); gsub(/NAME/, NAME); print; }
' "$0"
}
_main() {
# A wrapper around find to ignore noise directories
#
# ## Usage
#
# `NAME [<flags>] <searchpath> [...other find arguments...]
#
# NAME -h
# NAME .
# NAME ./somepath
# NAME . -type d
# NAME . -type f -name '*.js'
#
# Flag | Description
# ---- | -----------
# -V | Show version.
# -h | Usage and help text.
# -x | Enable xtrace debug logging.
#
# Flags _must_ be the first argument to `NAME`, before `searchterm`.
#
# Patterns to ignore are obtained from reading the following files:
#
# - `$HOME/.ffind`
# - `$PWD/.ffind`
# - `$(git rev-parse --absolute-git-dir)/../.ffind`
#
# The ignore file format is one entry per line, with an expression that
# find can consume. Blank lines and comments (#) are ignored:
#
# # This is a comment.
#
# -path *.git
# -path *node_modules
# -name *.pyc
while getopts Vhx opt; do
case $opt in
V) printf 'Version: %s\n' $VERSION
exit;;
h) help _main
printf '\n'
exit;;
x) set -x;;
esac
done
shift $(( OPTIND - 1 ))
local spath="${1:?'Search path missing.'}"
shift 1
exec 4>&2 2>/dev/null
local prune="$(cat \
"${HOME}/.ffind" \
"${PWD}/.ffind" \
"$(git rev-parse --absolute-git-dir)/../.ffind" |
awk '/^-/ { printf("%s%s", sep, $0); sep=" -o " }')"
exec 2>&4 4>&-
if [ -n "$prune" ]; then
prune="( ${prune} ) -prune"
fi
case "$@" in
*-print|*-print0) ;;
*) local add_print=1 ;;
esac
set -f
find "$spath" \
$prune \
-o "$@" \
${add_print+-print}
set +f
}
_main "$@"