<commit_before>#! /bin/bash

CONFIG_GIST_RAW_URL='https://gist.githubusercontent.com/tdd/470582/raw/6de3d88a3965501a72afa755e417775013cedf00'
CYAN=36
GREEN=32
PROMPT_GIST_RAW_URL='https://gist.githubusercontent.com/tdd/473838/raw/06ceecb51c7e73d4f705319cd0d876e0fe956795'
RED=31

if sed -r '' 2> /dev/null <<< ''; then
  sed_extended='-r'
  sed_inplace="-i'' "
else
  sed_extended='-E'
  sed_inplace="-i ''"
fi

function announce() {
  echo ''
  colorize $CYAN "$@"
  colorize $CYAN $(echo "$@" | sed 's/./=/g')
  echo ''
}

function colorize() {
  local color="$1"
  shift
  if tty -s <&1; then
    echo -e "\033[1;${color}m""$@""\033[0m"
  else
    echo "$@"
  fi
}

function config() {
  # ensure_local_config
  # ensure_prompt
  ensure_completion
}

function ensure_completion() {
  true # FIXME
}

function ensure_local_config() {
  announce 'Configuration globale'

  local path=$(get_local_config_path)
  local contents=$(curl -s "$CONFIG_GIST_RAW_URL")
  local username=$(get_config_entry user.name) email=$(get_config_entry user.email)

  if [ -f "$path" ]; then<commit_msg>Finalisation (?!) du configurateur Git<commit_after>#! /bin/bash
#
# Autopilot configurator for local Git config, Git-aware Bash prompt and Bash completion.
# Helps bootstrap Git training sessions much faster, but can help anyone else, I guess…
#
# (c) 2015 <NAME> <<EMAIL>>

CONFIG_GIST_RAW_URL='https://gist.githubusercontent.com/tdd/470582/raw/6de3d88a3965501a72afa755e417775013cedf00'
CYAN=36
GREEN=32
PROMPT_GIST_RAW_URL='https://gist.githubusercontent.com/tdd/473838/raw/f202bc3b8f6b8c7c40fe1d720610031fd5514d8e'
RED=31

if sed -r '' 2> /dev/null <<< ''; then
  sed_extended='-r'
  sed_inplace="-i'' "
else
  sed_extended='-E'
  sed_inplace="-i ''"
fi

function announce() {
  echo ''
  colorize $CYAN "$@"
  colorize $CYAN $(echo "$@" | sed 's/./=/g')
  echo ''
}

function colorize() {
  local color="$1"
  shift
  if tty -s <&1; then
    echo -e "\033[1;${color}m""$@""\033[0m"
  else
    echo "$@"
  fi
}

function config() {
  ensure_local_config
  ensure_prompt
  ensure_completion
}

function ensure_completion() {
  announce 'Vérification de la complétion'

  if complete -pr git &> /dev/null; then
    notice 'Une complétion est en place, tout roule.'
  else
    local file=$(get_proper_bash_config_file)
    local paths=$(get_proper_git_ps1_file)
    if [ -n "$paths" ]; then
      local earliest_file=$(echo "$paths" | head -n 1)
      notice "Chargement des définitions de complétion pour Git depuis ${earliest_file}…"
      echo -e "\n# Git completion definitions" >> "$file"
      echo "source '$earliest_file'" >> "$file"
    else
      ko 'Impossible de trouver une source de complétion Git :-(\n'
      return
    fi
  fi

  ok '\n\\o/ Vérification de la complétion terminée !\n'
}

function ensure_local_config() {
  announce 'Configuration globale'

  local path=$(get_local_config_path)
  local contents=$(curl -s "$CONFIG_GIST_RAW_URL")
  local username=$(get_config_entry user.name) email=$(get_config_entry user.email)

  if [ -f "$path" ]; then
{'fraction_non_alphanumeric': 0.1445861956166176, 'fraction_numerical': 0.0549558390578999, 'mean_word_length': 4.105175292153589, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 13, 'https://': 4, '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': '1011578', 'n_tokens_mistral': 1278, 'n_tokens_neox': 1155, 'n_words': 257}