aboutsummaryrefslogtreecommitdiff
path: root/bash/bashrc.d/hgrep.bash
blob: 2f7f8d54c7ad6ee0674e483917f8fa677fb675be (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 ! (($#)) ; then
        printf >&2 '%s: Need a pattern\n' "$FUNCNAME"
        exit 2
    fi
    if ! [[ -n $HISTFILE ]] ; then
        printf >&2 '%s: No HISTFILE\n' "$FUNCNAME"
        exit 2
    fi
    grep "$@" "$HISTFILE"
}