aboutsummaryrefslogtreecommitdiff
path: root/sh/shrc.d/hgrep.sh
diff options
context:
space:
mode:
Diffstat (limited to 'sh/shrc.d/hgrep.sh')
-rw-r--r--sh/shrc.d/hgrep.sh16
1 files changed, 16 insertions, 0 deletions
diff --git a/sh/shrc.d/hgrep.sh b/sh/shrc.d/hgrep.sh
new file mode 100644
index 00000000..b6143b37
--- /dev/null
+++ b/sh/shrc.d/hgrep.sh
@@ -0,0 +1,16 @@
+# Search shell history file for a pattern. If you put your whole HISTFILE
+# contents into memory, then you probably don't need this, as you can just do:
+#
+# $ history | grep PATTERN
+#
+hgrep() {
+ if [ "$#" -eq 0 ] ; then
+ printf >&2 'hgrep: Need a pattern\n'
+ exit 2
+ fi
+ if ! [ -n "$HISTFILE" ] ; then
+ printf >&2 'hgrep: No HISTFILE\n'
+ exit 2
+ fi
+ grep "$@" "$HISTFILE"
+}