summaryrefslogtreecommitdiffstats
path: root/services/lib
diff options
context:
space:
mode:
authortv <tv@nomic.retiolum>2014-03-13 18:13:56 +0100
committertv <tv@nomic.retiolum>2014-03-13 18:13:56 +0100
commit40cf4c6b46acff33527cec2363a952936dafcaae (patch)
treec84a22e755332bb8893a607b60286818fc98cc9c /services/lib
parent323ca2ae1a5eb668ae6577e7eb43c62c61735709 (diff)
services lib filter: initial commit
Diffstat (limited to 'services/lib')
-rwxr-xr-xservices/lib/filter54
1 files changed, 54 insertions, 0 deletions
diff --git a/services/lib/filter b/services/lib/filter
new file mode 100755
index 00000000..93853895
--- /dev/null
+++ b/services/lib/filter
@@ -0,0 +1,54 @@
+#! /bin/sh
+#
+# usage:
+# export PATH="//services/lib:$PATH"
+# cd services
+# ls | filter owner == $LOGNAME | filter hasnt mail
+#
+set -euf
+
+main() {
+ case $# in
+ 2) op1 "$@";;
+ 3) op2 "$@";;
+ *) echo 'You are made of stupid!' >&2; exit 23;;
+ esac
+}
+
+# op1 OP SCHEMA
+op1() {
+ case "$1" in
+ has)
+ xargs grep -H "^$2:" \
+ | cut -d: -f1
+ ;;
+ hasnt)
+ a=$(mktemp)
+ b=$(mktemp)
+ trap "rm $a $b; trap - EXIT INT QUIT" EXIT INT QUIT
+ cat > $a
+ cat $a | xargs grep -H "^$2:" | cut -d: -f1 > $b
+ diff -u $b $a | sed -n '/^++/d;s/^+\(.*\)/\1/p' | grep .
+ esac
+}
+
+# op2 SCHEMA OP RHS
+op2() {
+ case "$2" in
+ ==)
+ xargs grep -H "^$1:$3$" \
+ | cut -d: -f1
+ ;;
+ !=)
+ xargs grep -H "^$1:" \
+ | grep -v ":$1:$3" \
+ | cut -d: -f1
+ ;;
+ ~=)
+ xargs grep -H "^$1:.*$3.*$" \
+ | cut -d: -f1
+ ;;
+ esac
+}
+
+main "$@"