191 lines · 4.6 KB
#!/usr/bin/env bash

# Bash 4.0+ only. Faster than using tr or awk + no fork.
toLower() {
    if [[ $# -eq 0 ]]; then
        while IFS= read -r line; do
            echo "${line,,}"
        done
    else
        local str="$*"
        echo "${str,,}"
    fi
}

# Return a string corresponding to the current OS.
which_os() {
    case "$OSTYPE" in
    darwin*)
        printf "darwin"
        ;;
    linux*)
        if [[ -f /etc/os-release ]]; then
            # shellcheck disable=SC1091
            source /etc/os-release
            printf "%s" "${ID,,}"
        else
            printf "linux"
        fi
        ;;
    esac
}

# Choose a Charm repo name with Gum.
pickCharmRepo() {
    getCharmRepos | gum filter --height=10 --header "$1"
}

# Interactively choose a Charm repo.
charm_clone() {
    local repo