<commit_before>function tfplan() {
  if [[ -d "./.terraform/" ]]; then

    workspace_name=$(terraform workspace show)
    if [[ -f "tfvars/${workspace_name}.tfvars" ]]; then
      echo "Running terraform plan with ${workspace_name}.tfvars..."
      WORKSPACE_ARG="-var-file=tfvars/${workspace_name}.tfvars"
    fi

    if [[ -f "tfvars/secrets.tfvars" ]]; then
      echo "Running terraform plan with secrets.tfvars..."
      SECRETS_ARG="-var-file=tfvars/secrets.tfvars"
    fi

    terraform plan -out=run.plan $WORKSPACE_ARG $SECRETS_ARG $*
  else
    echo "You're not in a terraform directory!"
  fi
}

function tf_make_module() {
  local module_name=$1

  if [[ ! -d "./.terraform/" ]]; then
    echo "You're not in a terraform directory!"
    exit 1
  fi

  mkdir -p "./modules/${module_name}"
  echo "# ${module_name}.tf\n" >"./modules/${module_name}/main.tf"
  echo "# ${module_name}.tf\n" >"./modules/${module_name}/variables.tf"
  echo "# ${module_name}.tf\n" >"./modules/${module_name}/outputs.tf"
  echo "Successfully created ${module_name} module!"
}

function install_tf_commit_hook() {
  cat ~/.dotfiles/terraform/terraform-pre-commit-hook.yml >.pre-commit-config.yml
}<commit_msg>Consolidates tfplan + tfrefresh logic into abstract func<commit_after>function tf_with_vars() {
  local cmd=$1
  shift # Removes arg 1 from arg list

  if [[ ! -d "./.terraform/" ]]; then
    echo "You're not in a terraform directory!"
    exit 1
  fi

  local workspace_name=$(terraform workspace show)
  if [[ -f "tfvars/${workspace_name}.tfvars" ]]; then
    echo "Running terraform plan with ${workspace_name}.tfvars..."
    WORKSPACE_ARG="-var-file=tfvars/${workspace_name}.tfvars"
  fi

  if [[ -f "tfvars/secrets.tfvars" ]]; then
    echo "Running terraform plan with secrets.tfvars..."
    SECRETS_ARG="-var-file=tfvars/secrets.tfvars"
  fi

  if [[ "$cmd" == "plan" ]]; then
    terraform plan -out=run.plan $WORKSPACE_ARG $SECRETS_ARG $*
  else
    terraform $cmd $WORKSPACE_ARG $SECRETS_ARG $*
  fi
}

function tfplan() {
  tf_with_vars plan
}

function tfrefresh() {
  tf_with_vars refresh
}

function tf_make_module() {
  local module_name=$1

  if [[ ! -d "./.terraform/" ]]; then
    echo "You're not in a terraform directory!"
    exit 1
  fi

  mkdir -p "./modules/${module_name}"
  echo "# ${module_name}.tf\n" >"./modules/${module_name}/main.tf"
  echo "# ${module_name}.tf\n" >"./modules/${module_name}/variables.tf"
  echo "# ${module_name}.tf\n" >"./modules/${module_name}/outputs.tf"
  echo "Successfully created ${module_name} module!"
}

function install_tf_commit_hook() {
  cat ~/.dotfiles/terraform/terraform-pre-commit-hook.yml >.pre-commit-config.yml
}
{'fraction_non_alphanumeric': 0.16349384098544234, 'fraction_numerical': 0.0026129152668906306, 'mean_word_length': 3.573378839590444, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1272677', 'n_tokens_mistral': 953, 'n_tokens_neox': 959, 'n_words': 209}