#!/usr/bin/env bash # Print the names of all public and private Charm repos. getCharmRepos() { getRepos() { gh repo list charmbracelet --visibility="$1" --json name } getAllRepos() { printf '%s %s' "$(getRepos "public")" "$(getRepos "private")" | jq -s 'add' } getAllRepos | jq .[].name | tr -d '"' | sort } # Choose a Charm repo name with Gum. pickCharmRepo() { getCharmRepos | gum filter --height=10 --header "$1" } # Interactively choose a Charm repo. charm_clone() { local repo repo="$(pickCharmRepo "Clone which Charm™ repo?")" if [[ -z "$repo" ]]; then printf "Okay, never mind.\n" return 1 fi git clone "git@github.com:charmbracelet/$repo" "$HOME/src/$repo" } # Interactively use "go get" against a Charm repo. go_get_charm() { local repo repo="$(pickCharmRepo "Which Charm™ repo do you want to ‘go get?’")" if [[ -z "$repo" ]]; then printf "Okay, never mind.\n" return 1 fi go get "github.com/charmbracelet/$repo" } # Returns the number of CPU cores available on the system. num_cores() { nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo "Could not determine core count" } # Return a string corresponding to the current OS. which_os() { case "$OSTYPE" in darwin*) printf "darwin" ;; linux*) if [[ -f "/etc/issue" ]]; then issue=$(cat /etc/issue) if [[ $issue =~ "NixOS" ]]; then printf "nixos" elif [[ $issue =~ "Void" ]]; then printf "void" elif [[ $issue =~ "Arch" ]]; then printf "arch" elif [[ $issue =~ "Debian" ]]; then printf "debian" else printf "linux" fi fi ;; esac printf "" } # Return 1 if a given command exists, and 0 if not. command_exists() { if command -v "$1" &>/dev/null; then printf 1 return fi printf 0 } # Return the preferred diff tool for the given OS. gitdiff() { if [[ $(which_os) == darwin ]]; then opendiff else vimdiff fi } #shellcheck disable=1090 decryptAndSource() { command -v gpg >/dev/null 2>&1 && source <(gpg --decrypt <<<"$1" 2>/dev/null) }