# shellcheck shell=sh disable=SC2034,SC2154,SC3043

### Section: cat zip file, following the list of files to cat ...
___x_cmd_zuz_cat(){
    local ___X_CMD_ZUZ_NOT_UI=1
    local target_file="${1:-filename}"; shift
    case "$target_file" in
        *.tar)
            # LC_ALL="$___X_CMD_LOCALE_DEF_C" ___x_cmd_zuz_run tar -t <"$target_file"  # bsdtar
            LC_ALL="$___X_CMD_LOCALE_DEF_C" ___x_cmd_cmds tar Oxf - "$@" <"$target_file"  # bsdtar
            ;;
        *.tar.gz)
            # LC_ALL="$___X_CMD_LOCALE_DEF_C" ___x_cmd_zuz_run tar -t <"$target_file"  # bsdtar
            LC_ALL="$___X_CMD_LOCALE_DEF_C" ___x_cmd_cmds tar Oxf - "$@" <"$target_file"  # bsdtar
            ;;

        *.tar.xz)
            if ___x_cmd_hasbin xz; then
                LC_ALL="$___X_CMD_LOCALE_DEF_C" ___x_cmd_cmds tar Oxf "$target_file" "$@"   # bsdtar
            else
                # ___x_cmd_zuz_run ___x_cmd 7z x -so "$target_file" | ___x_cmd_cmds tar -t
                ___x_cmd 7z x -so "$target_file" | ___x_cmd_cmds tar Oxf - "$@"
            fi
            ;;

        *.tar.Z)
            LC_ALL="$___X_CMD_LOCALE_DEF_C" ___x_cmd_zuz_run tar -t <"$target_file"  # bsdtar
            ;;

        *.bz2)
            LC_ALL="$___X_CMD_LOCALE_DEF_C" ___x_cmd_zuz_run tar -t <"$target_file"  # bsdtar
            ;;
        *.tgz)
            LC_ALL="$___X_CMD_LOCALE_DEF_C" ___x_cmd_zuz_run tar Oxf "$target_file" "$@"
            # ___x_cmd_zuz_run gzip --list "$target_file"
            ;;
        *.gz)
            ___x_cmd_zuz_run gzip -c -d "$target_file"
            # ___x_cmd_zuz_run gzip --list "$target_file"
            ;;

        *.xz)   N=zuz M="Unsupported to list xz file."  log:ret:1 ;;
        *.zst)  N=zuz M="Unsupported to list zst file." log:ret:1 ;;

        *.zip)
                ___x_cmd_zuz_run ___x_cmd 7z l -ba "$target_file"  # bsdtar
                ;;

        *.rar)  N=zuz M="Unsupported to list rar file."  log:ret:1 ;;

        *.7z)
            ___x_cmd_zuz_run ___x_cmd 7z l -ba "$target_file" | ___x_cmd_cmds_awk '{ print $NF }'
            ;;
        *)      N=zuz M="Unsupported to list file -> $target_file." log:ret:1 ;;
    esac
}
### EndSection
