-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilter
More file actions
executable file
·63 lines (49 loc) · 1.31 KB
/
Copy pathfilter
File metadata and controls
executable file
·63 lines (49 loc) · 1.31 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
#!/usr/bin/env nix-shell
#! nix-shell -i bash -p bash xe coreutils
# shellcheck shell=bash
export PS4='$ '
# shellcheck disable=SC2120
usage() {
# shellcheck disable=SC2059
[[ "$#" -eq 0 ]] || printf "$@" >&2
cat >&2 <<EOF
usage: filter [!] <command...>
stest [!] <test(1) arguments>
Test each item given on standard input against <command>,
and print item if <command> exits positively.
If the arguments begin with "!", their result will be
negated; this means that items will be printed if the
<command> exited unsuccessfully.
Kylie McClain <kylie@somas.is>
EOF
[[ "$#" -eq 0 ]] || exit 1
exit 64 # EX_USAGE
}
set -euo pipefail
sh_conjunct='&&'
# shellcheck disable=SC2119
case "$1" in
--help) usage ;;
'!')
sh_conjunct='||'
shift
;;
esac
pe() {
xe -LL -j0 "$@" | sort -snk1 | cut -d' ' -f2-
}
case "${0##*/}" in
stest)
test_error=
# shellcheck disable=SC2065,SC2319
test "$@" >/dev/null 2>&1 || test_error=$?
if [[ "${test_error}" -eq 2 ]]; then
# syntax error; test only exits with 1 in bash on files not testing positively
exec test "$@"
fi
set -- test "$@"
;;
esac
set -- "${@@Q}"
# shellcheck disable=SC2016,SC2145
exec pe -s "$*"' "$1" '"$sh_conjunct"' printf "%s\n" "$1"'