# shellcheck shell=dash
# rename to top

___x_cmd_history_stat(){
    if ___x_cmd_is_stdout2tty && ___x_cmd_runmode_allow_chatty; then
        ___x_cmd_history_stat_app "$@" # | less -R
    else
        ___x_cmd_history_stat_raw "$@"
    fi
}

___x_cmd_history_stat_raw(){
    ___x_cmd_history_ls \
        | ___x_cmd_cmds awk -f "$___X_CMD_ROOT_MOD/history/lib/awk/stat.awk" \
        | ___x_cmd_cmds sort -rn -k 1
}

___x_cmd_history_stat_app(){
    ___x_cmd_history_stat_raw \
        | ___x_cmd_cmds awk -v TOP="${1:-15}" -f "$___X_CMD_ROOT_MOD/history/lib/awk/topbar.awk"
}

