<commit_before>#!/usr/bin/env bash

# @name asdfup
# @brief Install and configure asdf version manager
# @description
#     This can be used to boostrap asdf on a clean machine.
#     Enables plugins to be configured via file.
#     Designed to be used as pre/post-up hook for [rcm](https://github.com/thoughtbot/rcm).
# @see https://asdf-vm.com

[[ ${TRACE-} ]] && set -x

set -euo pipefail

ASDF_DIR=${ASDF_DIR:-$HOME/.asdf}

function asdf_dir_bootstrap() {
	if [[ ! -d ${ASDF_DIR?} ]]; then
		git clone https://github.com/asdf-vm/asdf.git "$ASDF_DIR"
		(
			cd "$ASDF_DIR"
			tag=$(git describe --abbrev=0 --tags)
			git checkout -q "tags/${tag}" -b "$tag"
		)
	fi
}

# @brief adds asdf plugins that are not already registered
# @description
#     - Reads arguments to `asdf plugin-add` from stdin or file argument.
#     - Ignores lines starting with '#'
#     - Ignores lines starting with name of plug that is currently installed
#     - Runs `asdf plugin-add` on the rest
asdf_plugins_init() {
	local -r ignore_prefixes=$(printf '# %s' "$(asdf plugin-list)" | xargs echo)
	sed "/^${ignore_prefixes// /\\|}/d" "${1-}" | xargs -r -t -L1 asdf plugin-add
}

function strong_echo() {
	echo -e "\033[1m${*}\033[m"
}

function main() {
	asdf_dir_bootstrap

	# shellcheck source=/dev/null
	source "${ASDF_DIR}/asdf.sh"

	# initialize plugins
	if [[ -f ~/.asdf-plugins ]]; then
		asdf_plugins_init ~/.asdf-plugins
	fi

	local -r pad="    "
	strong_echo ASDF VERSION
	printf "\n%s\n\n" "${pad}$(asdf version)"
	strong_echo "ASDF ENVIRONMENT VARIABLES"
	printf "\n%s\n\n" "$(env | grep '^ASDF_' | sed "s/^/${pad}/")"
	strong_echo "ASDF PLUGINS:"
	printf "\n%s\n\n" "$(asdf plugin list --urls | sed "s/^/${pad}/")"
}

main<commit_msg>asdf-up<commit_after>#!/usr/bin/env bash

# @name asdfup
# @brief Install and configure asdf version manager
# @description
#     This can be used to boostrap asdf on a clean machine.
#     Enables plugins to be configured via file.
#     Designed to be used as pre/post-up hook for [rcm](https://github.com/thoughtbot/rcm).
# @see https://asdf-vm.com

[[ ${TRACE-} ]] && set -x

set -euo pipefail

ASDF_DIR=${ASDF_DIR:-$HOME/.asdf}

# @brief adds asdf plugins that are not already registered
# @description
#     - Reads arguments to `asdf plugin-add` from stdin or file argument.
#     - Ignores lines starting with '#'
#     - Ignores lines starting with name of plug that is currently installed
#     - Runs `asdf plugin-add` on the rest
asdf_plugins_init() {
	local -r ignore_prefixes=$(printf '# %s' "$(asdf plugin-list)" | xargs echo)
	sed -e "/^${ignore_prefixes// /\\|}/d" "${1-}" | xargs -r -t -L1 asdf plugin-add
}

# shellcheck disable=SC2001
function info_section() {
  local -r heading=$1
	>&2 echo -e "\033[1m${heading}\033[m"
  >&2 echo
  >&2 sed -e "s/^/    /"
  >&2 echo
}

function main() {
	if ! [[ -d $ASDF_DIR ]]; then
		git clone https://github.com/asdf-vm/asdf.git "$ASDF_DIR"
  fi

	# shellcheck source=/dev/null
	source "${ASDF_DIR}/asdf.sh"

  asdf update 2>/dev/null

	# initialize plugins
	if [[ -f ~/.asdf-plugins ]]; then
		asdf_plugins_init ~/.asdf-plugins
	fi

  # print asdf info
  asdf version | info_section "ASDF VERSION"
  env | grep '^ASDF_' | info_section "ASDF ENVIRONMENT VARIABLES"
  asdf plugin list --urls | info_section "ASDF PLUGINS"
}

main
{'fraction_non_alphanumeric': 0.1582755501959602, 'fraction_numerical': 0.008742839915586373, 'mean_word_length': 3.2923673997412677, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5777573', 'n_tokens_mistral': 1286, 'n_tokens_neox': 1229, 'n_words': 362}