# shellcheck disable=SC2016

___x_cmd_history_rec(){
    [ $# -gt 0 ]    ||  set -- --help

    local op="$1" ; shift
    case "$op" in
        -h|--help)      ___x_cmd help -m history rec ;;
        add|findlongestsubstr|findmaxtokens) # findlogestprefix
                        ___x_cmd_history_rec_"$op" "$@" ;;
    esac
}

___x_cmd_history_rec_add(){
    local fp="$1"
    local data="$2"
    local md5="${3:-"---"}"

    printf "%s  %s\n" "$md5" "$fp" >>"$data"
}

___x_cmd_history_rec_findlongestsubstr(){
    local fp="$1"
    local querycmd="$2"

    {
        printf "%s  %s\n"   "///"         "$querycmd"
        ___x_cmd_cmds cat "$fp"
    } | ___x_cmd_cmds sort -r -k 2 | \
        ___x_cmd_cmds awk -v q="$querycmd" \
            -f "$___X_CMD_ROOT_MOD/history/lib/rec/findlongestsubstr.awk"
}

___x_cmd_history_rec_findmaxtokens(){
    local fp="$1"
    local querycmd="$2"

    ___x_cmd_cmds awk -v q="$querycmd" \
        -f "$___X_CMD_ROOT_MOD/history/lib/rec/findmaxtokens.awk" <"$fp"
}

# Useless strategy
___x_cmd_history_rec_findlongestprefix(){
    local fp="$1"
    local querycmd="$2"

    ___x_cmd_cmds awk -v q="$querycmd" \
        -f "$___X_CMD_ROOT_MOD/history/lib/rec/findmaxtokens.awk" <"$fp"
}


