# shellcheck shell=dash disable=SC2016

xrc:mod:lib     skill   lr/app  lr/data

___x_cmd_skill_lr(){
    [ "$#" -gt 0 ] || set - --auto

    local op="$1"; shift
    case "$op" in
        -h|--help)      ___x_cmd help -m skill lr;    return 0 ;;
        --prompt)       ___x_cmd_skill_lr___prompt        "$@" ;;

        --fzapp)        ___x_cmd_skill_lr___fzapp         "$@" ;;
        --fzapp_)       ___x_cmd_skill_lr___fzapp_        "$@" ;;
        --fzdata)       ___x_cmd_skill_lr___fz_data       "$@" ;;
        --fzpreview)    ___x_cmd_skill_lr___fz_preview    "$@" ;;
        --auto)         ___x_cmd_skill_lr___auto          "$@" ;;

        --raw)          ___x_cmd_skill_lr___raw           "$@" ;;
        --csv)          ___x_cmd_skill_lr___csv           "$@" ;;
        --tsv)          ___x_cmd_skill_lr___tsv           "$@" ;;
        --id)           ___x_cmd_skill_lr___id            "$@" ;;
        --github)       ___x_cmd_skill_lr___github        "$@" ;;
        --xcmd)         ___x_cmd_skill_lr___xcmd          "$@" ;;
        --awsome)       ___x_cmd_skill_lr___awsome        "$@" ;;
        -f|--filter)    ___x_cmd_skill_lr___filter        "$@" ;;
        *)              ___x_cmd_skill_lr___app "$op"     "$@" ;;
    esac
}

___x_cmd_skill_lr___prompt(){
    printf "%s\n" '
use `x skill lr` to list all of the remote skills from clawhub, x-cmd, google.
Each skill is organized in one line in this format - skill-id<tab><desc><NEWLINE>

If you want to reuse the skill in the next session, use `x skill add <skill-id>`.

## If the skill is prefixed with x-mod/<mod>

1. You can read more examples and instruction using `x <mod> --help`
2. Normally, if you want to reuse this skill in the next session, you can simple add a note to the AGENTS.md or other memory file without installation in the skill folder.

# Other

1. `x skill info <skill-id>` will download the skill data and provide a summary and the skill local folder path. You can explore the local folder for more information.
'
}

___x_cmd_skill_lr___auto(){
    if      ___x_cmd_is_stdout2tty; then        ___x_cmd_skill_lr___fzapp "$@"
    else                                        ___x_cmd_skill_lr___tsv   "$@"
    fi
}


___x_cmd_skill_lr___raw(){
    ___x_cmd_skill_lr___xcmd
    ___x_cmd_skill_lr___awsome
}

___x_cmd_skill_lr___id(){
    ___x_cmd_skill___data_check || return $?
    {
        local header; read -r header

        local IFS="$___X_CMD_UNSEENCHAR_HT"
        local x_id=""; local x_other
        while read -r x_id x_other; do
            printf "%s\n" "$x_id"
        done
    }  < "$___X_CMD_SKILL_FULL_INDEX_FILE"
}

___x_cmd_skill_lr___tsv(){
    ___x_cmd_skill_lr___raw
}

___x_cmd_skill_lr___csv(){
    ___x_cmd_skill_lr___raw | ___x_cmd tsv tocsv
}

___x_cmd_skill_lr___filter(){
    local filter_str="$*"
    [ -n "$filter_str" ] || N=skill M="Please provide filter string" log:ret:64

    ___x_cmd_skill_lr___csv | ___x_cmd fzf --filter="$filter_str"
}

