<commit_before># MetaMan
# cargo.sh - implements meta.sh for cargo
#
# Copyright (C) 2017 <NAME>
#
# This software may be modified and distributed under the terms
# of the MIT license. See the LICENSE file for details.

# Cargo always reports as unloaded, so that it will be loaded, so that PATH
# stays in the proper order. Harmless since we guarantee PATH will be deduped.
__mm_cargo_is_loaded() { false; }

__mm_cargo_is_installed() {
  [[ -x "$(__mm_cargo_get_home)/bin/cargo" ]] || __is_command cargo
}

__mm_cargo_load() {
  export CARGO_HOME="$(__mm_cargo_get_home)"
  export PATH="${CARGO_HOME}/bin:${PATH}"
}

__mm_cargo_is_comp_loaded() {
  ! __is_command rustup || (__is_function _cargo && __is_function _rustup)
}

__mm_cargo_load_comp_zsh() {
  rustup completions zsh >"${USER_ZSH_FUNCTIONS}/_rustup"

  local toolchain_dir="$(__mm_cargo_get_toolchain_dir)"

  if [[ -d "${toolchain_dir}" ]]; then
    cp "${toolchain_dir}/share/zsh/site-functions/_cargo" \
       "${USER_ZSH_FUNCTIONS}/_cargo"
  fi

  cat >&2 <<EOT
Completions for cargo and rustup have been installed. To activate, restart the
current shell: \`${DCP_SHELL_EXEC_CMD[*]}'
EOT
}

__mm_cargo_load_comp_bash() {
  rustup completions bash >"${USER_BASH_COMPLETION_D}/rustup.bash-completion"
  . "${USER_BASH_COMPLETION_D}/rustup.bash-completion"

  local toolchain_dir="$(__mm_cargo_get_toolchain_dir)"

  if [[ -d "${toolchain_dir}" ]]; then
    cp "${toolchain_dir}/etc/bash_completion.d/cargo" \
       "${USER_BASH_COMPLETION_D}/cargo"
    . "${USER_BASH_COMPLETION_D}/cargo"
  fi
}

__mm_cargo_get_home() {
  printf "%s" "${CARGO_HOME:-${HOME}/.cargo}"
}

__mm_cargo_get_toolchain_dir() {
  local toolchain="$(rustup toolchain list | sed -e '/(default)$/!d' \<commit_msg>Eliminate __mm_cargo_get_home<commit_after># MetaMan
# cargo.sh - implements meta.sh for cargo
#
# Copyright (C) 2017 <NAME>
#
# This software may be modified and distributed under the terms
# of the MIT license. See the LICENSE file for details.

# Cargo always reports as unloaded, so that it will be loaded, so that PATH
# stays in the proper order. Harmless since we guarantee PATH will be deduped.
__mm_cargo_is_loaded() { false; }

__mm_cargo_is_installed() {
  [[ -x "${CARGO_HOME:-${HOME}/.cargo}/bin/cargo" ]] || __is_command cargo
}

__mm_cargo_load() {
  export CARGO_HOME="${CARGO_HOME:-${HOME}/.cargo}"
  export PATH="${CARGO_HOME}/bin:${PATH}"
}

__mm_cargo_is_comp_loaded() {
  ! __is_command rustup || { __is_function _cargo && __is_function _rustup; }
}

__mm_cargo_load_comp_zsh() {
  rustup completions zsh >"${USER_ZSH_FUNCTIONS}/_rustup"

  local toolchain_dir="$(__mm_cargo_get_toolchain_dir)"

  if [[ -d "${toolchain_dir}" ]]; then
    cp "${toolchain_dir}/share/zsh/site-functions/_cargo" \
       "${USER_ZSH_FUNCTIONS}/_cargo"
  fi

  cat >&2 <<EOT
Completions for cargo and rustup have been installed. To activate, restart the
current shell: \`${DCP_SHELL_EXEC_CMD[*]}'
EOT
}

__mm_cargo_load_comp_bash() {
  rustup completions bash >"${USER_BASH_COMPLETION_D}/rustup.bash-completion"
  . "${USER_BASH_COMPLETION_D}/rustup.bash-completion"

  local toolchain_dir="$(__mm_cargo_get_toolchain_dir)"

  if [[ -d "${toolchain_dir}" ]]; then
    cp "${toolchain_dir}/etc/bash_completion.d/cargo" \
       "${USER_BASH_COMPLETION_D}/cargo"
    . "${USER_BASH_COMPLETION_D}/cargo"
  fi
}

__mm_cargo_get_toolchain_dir() {
  local toolchain="$(rustup toolchain list | sed -e '/(default)$/!d' \
{'fraction_non_alphanumeric': 0.13733410271206, 'fraction_numerical': 0.0028851702250432777, 'mean_word_length': 4.89625850340136, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, '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': '2705981', 'n_tokens_mistral': 1347, 'n_tokens_neox': 1304, 'n_words': 277}