aboutsummaryrefslogtreecommitdiff
path: root/sh/shrc.d/hgrep.sh
blob: fe297ab332fb58ce65f62c767c8d7b225a7da079 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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'
        return 2
    fi
    if [ -z "$HISTFILE" ] ; then
        printf >&2 'hgrep(): No HISTFILE\n'
        return 2
    fi
    grep "$@" "$HISTFILE"
}