about summary refs log tree commit diff stats
path: root/contrib
diff options
context:
space:
mode:
authorRory Bradford <roryrjb@gmail.com>2020-08-30 12:15:39 +0100
committerRory Bradford <roryrjb@gmail.com>2020-08-30 12:15:39 +0100
commit1c5aba7f1b2a53cdcaf896df118f3c7b42c0251c (patch)
tree2350946cee55c9a564b857f23d3dd5b396fda65b /contrib
parent4d872677b173d5380e5ab63b17e45d876cc3e864 (diff)
downloadrf-1c5aba7f1b2a53cdcaf896df118f3c7b42c0251c.tar.gz
Add rfgrep contrib script
Signed-off-by: Rory Bradford <roryrjb@gmail.com>
Diffstat (limited to 'contrib')
-rw-r--r--contrib/rfgrep/Makefile6
-rwxr-xr-xcontrib/rfgrep/rfgrep23
2 files changed, 29 insertions, 0 deletions
diff --git a/contrib/rfgrep/Makefile b/contrib/rfgrep/Makefile
new file mode 100644
index 0000000..1468fec
--- /dev/null
+++ b/contrib/rfgrep/Makefile
@@ -0,0 +1,6 @@
+BIN = rfgrep
+PREFIX = /usr/local
+
+install:
+	mkdir -p $(DESTDIR)$(PREFIX)/bin
+	install -m755 $(BIN) $(DESTDIR)$(PREFIX)/bin/
diff --git a/contrib/rfgrep/rfgrep b/contrib/rfgrep/rfgrep
new file mode 100755
index 0000000..d1f262e
--- /dev/null
+++ b/contrib/rfgrep/rfgrep
@@ -0,0 +1,23 @@
+#!/bin/sh
+
+set -e
+
+files=
+edit=
+
+EDITOR=${EDITOR:-vim}
+
+while getopts 'ef' opt; do
+    case $opt in
+        e) edit=1; shift ;;
+        f) files=1; shift ;;
+    esac
+done
+
+if [ "$files" ]; then
+    rf '*' | xargs grep -Ir "$1" | awk -F':' '{print $1}' | sort | uniq
+elif [ "$edit" ]; then
+    $EDITOR $(rf '*' | xargs grep -Ir "$1" | awk -F':' '{print $1}' | sort | uniq)
+else
+    rf '*' | xargs grep -Ir "$1"
+fi