


# TODO: la -> ls

# autoset with mirror according to the speed.

___x_cmd_pacman_mirror_la(){
    [ $# -gt 0 ]    ||  set -- --fzf

    ___x_cmd_pacman_mirror_la___auto
}

___x_cmd_pacman_mirror_la___auto(){

    if ___x_cmd_is_stdout2tty; then
        ___x_cmd_pacman_mirror_la___fzf
    else
        ___x_cmd_pacman_mirror_la___tsv
    fi
}

___x_cmd_pacman_mirror_la___raw(){
    ___x_cmd ccmd 30h -- ___x_cmd httpget https://archlinux.org/mirrorlist/all/
}

___x_cmd_pacman_mirror_la___tsv(){
    ___x_cmd_pacman_mirror_la___raw | ___x_cmd_cmds awk '
    $1=="##"{
        code = $2
        next
    }

    $1=="#Server"{
        printf("%s\t%s\n", code, $3)
    }
    '
}

___x_cmd_pacman_mirror_la___fzf(){
    ___x_cmd_pacman_mirror_la___tsv | {
        ___x_cmd_cmds awk -v FS="\t" '{
            if ($2 ~ /https:/) {
                printf("\033[0;36m%-15s\t" "\033[0m" "%s\n", $1, $2);
            } else {
                printf("\033[2;36m%-15s\t" "\033[0;2m" "%s\n", $1, $2);
            }

        }'
    } | {
        ___x_cmd fzf --reverse --ansi
    }
}
