<commit_before>#!/bin/sh

# Clone and link terminal themes to appropriate directories.
init_terminal_themes() {
  log_info "Initializing terminal color schemes"

  __clone_iterm2_color_schemes
  __link_iterm2_color_schemes_to_other_terminal_theme_dirs
}

# Update the alacritty.yml file's colors based on a given theme name.
change_alacritty_theme() {
  local themeName="${1}"
  local alacrittyConfigFile="${USER_CONF:-${HOME}/.config}/alacritty/alacritty.yml"
  local alacrittyThemesDir="${WS}/iTerm2-Color-Schemes/alacritty"
  local newThemeFile="${alacrittyThemesDir}/${themeName}.yml"

  if [ -z "${themeName}" ]; then
    err "No theme name provided"
    return 1
  elif [ ! -d "${alacrittyThemesDir}" ]; then
    err "Could not find alacritty themes dir at:" \
      "${BLUE}${alacrittyThemesDir}${NC}"
    return 2
  elif [ ! -f "${newThemeFile}" ]; then
    err "Theme file ${BLUE}${newThemeFile}${NC} not found"
    return 3
  fi

  # Update the alacritty.yml file's "colors" attribute.
  yq eval-all -i 'select(fileIndex==0).colors = select(fileIndex==1) |
  select(fileIndex==0)' \
    "${alacrittyThemesDir}" \
    "${newThemeFile}"
}

__clone_iterm2_color_schemes() {
  local gitUrl="https://github.com/mbadolato/iTerm2-Color-Schemes.git"
  local destDir="${WS:-${HOME}/workspace}/$(basename "${gitUrl%.git}")"

  if [ -d "${destDir}" ]; then
    log_info "Updating iTerm2 Color Schemes repo"
    git -C "${destDir}" reset --hard
    git -C "${destDir}" clean -df
    git -C "${destDir}" pull
  else
    log_info "Cloning iTerm2 Color Schemes repo"
    git clone --depth 1 "${gitUrl}" "${destDir}"<commit_msg>Adding more safety checks to alacritty theme update function<commit_after>#!/bin/sh

# Clone and link terminal themes to appropriate directories.
init_terminal_themes() {
  log_info "Initializing terminal color schemes"

  __clone_iterm2_color_schemes
  __link_iterm2_color_schemes_to_other_terminal_theme_dirs
}

# Update the alacritty.yml file's colors based on a given theme name.
change_alacritty_theme() {
  local themeName="${1}"
  local alacrittyConfigFile="${USER_CONF:-${HOME}/.config}/alacritty/alacritty.yml"
  local alacrittyThemesDir="${WS}/iTerm2-Color-Schemes/alacritty"
  local newThemeFile="${alacrittyThemesDir}/${themeName}.yml"

  if [ ! -x "$(command -v yq)" ]; then
    err "yq command line tool not found on PATH"
    return 1
  elif [ -z "${themeName}" ]; then
    err "No theme name provided"
    return 2
  elif [ ! -d "${alacrittyThemesDir}" ]; then
    err "Could not find alacritty themes dir at:" \
      "${BLUE}${alacrittyThemesDir}${NC}"
    return 3
  elif [ ! -f "${newThemeFile}" ]; then
    err "Theme file ${BLUE}${newThemeFile}${NC} not found"
    return 4
  fi

  # Update the alacritty.yml file's "colors" attribute.
  yq eval-all -i 'select(fileIndex==0).colors = select(fileIndex==1) |
  select(fileIndex==0)' \
    "${alacrittyThemesDir}" \
    "${newThemeFile}"
}

__clone_iterm2_color_schemes() {
  local gitUrl="https://github.com/mbadolato/iTerm2-Color-Schemes.git"
  local destDir="${WS:-${HOME}/workspace}/$(basename "${gitUrl%.git}")"

  if [ -d "${destDir}" ]; then
    log_info "Updating iTerm2 Color Schemes repo"
    git -C "${destDir}" reset --hard
    git -C "${destDir}" clean -df
    git -C "${destDir}" pull
  else
    log_info "Cloning iTerm2 Color Schemes repo"
    git clone --depth 1 "${gitUrl}" "${destDir}"
{'fraction_non_alphanumeric': 0.14761343547436653, 'fraction_numerical': 0.009133765468473777, 'mean_word_length': 4.151745068285281, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '7744', 'n_tokens_mistral': 1222, 'n_tokens_neox': 1191, 'n_words': 290}