# shellcheck shell=dash
___x_cmd log init grep

xrc:mod:lib     grep        fzf/_index

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

    local op="$1"; shift
    case "$op" in
        --help)             ___x_cmd help -m grep       "$@" ;;
        --fzdata)           ___x_cmd_grep___fz_data     "$@" ;;
        --fzfapppreview)    ___x_cmd_grep___"${op#--}"  "$@" ;;

        --fz|--fzfapp)      ___x_cmd_grep___fzfapp      "$@" ;;

        --auto)             ___x_cmd_grep___auto        "$@" ;;
        --|--cmd)           ___x_cmd_grep___cmd         "$@" ;;
        *)                  ___x_cmd_grep___cmd "$op"   "$@" ;;
    esac
}

___x_cmd_grep___cmd(){
    # We can consider using cosmo gnu grep
    ___x_cmd_cmds grep "$@"
}

___x_cmd_grep___auto(){
    if ___x_cmd_is_stdout2tty && ___x_cmd_runmode_allow_manual ; then
        ___x_cmd_grep___fzfapp "$@"
    else
        ___x_cmd_grep___cmd "$@"
    fi
}
