export HISTCONTROL=ignoredups:ignorespace

case ${HISTORY_STYLE:-default} in
    per-shell)
        # save hist file per shell, deleting on close
        export HISTFILE="${XDG_CACHE_HOME:-${HOME}/.cache}/${0##*/}-history/history-$$"
        mkdir -p "${HISTFILE%history-$$}"
        trap '/bin/rm -f -- "$HISTFILE" 2>/dev/null' EXIT TERM KILL QUIT
        ;;
    default)
        ;;
esac

# hist-grep: search shell history
hg() {
    if [ "$1" ] ; then
        grep -i "$*" "$HISTFILE" | grep -v '^hg' | head -n 20
    fi
}

