<commit_before>#!/usr/bin/env bash -e
#
echo ''

info () {
  printf "  [ \033[00;34mINFO\033[0m ] $1 \n"
}

success () {
  printf "\r\033[2K  [ \033[00;32mOK\033[0m ] $1\n"
}

fail () {
  printf "\r\033[2K  [\033[0;31mFAIL\033[0m] $1\n"
  echo '' 
  exit
}


update() {
  info "Updating dotfiles"
  git pull origin master
  #git submodule init
  #git submodule update
}

download() {
  info "=== Downloading dotfiles"
  git clone --recursive git://git.merikan.com/dotfiles.git $DOTFILES_ROOT
}

backup() {
  info "=== Backing up local dotfiles to directory $backupdir"
  mkdir -p $backupdir

  local files=( $(find $DOTFILES_ROOT -maxdepth 2 -name \*.symlink) )
  for source in "${files[@]}"; do
    local dest="$destdir/.`basename \"${source%.*}\"`"
    if [ -L "$dest" ] && [ "$dest" -ef $source ]
    then
      info "$(basename $dest) is already a symlink pointing to $source, no need to backup"
      rm $dest
    elif [ -f $dest ] || [ -d $dest ] || [ -L "$dest" ]
    then
      mv $dest $backupdir
      success "moved $dest to $backupdir"
    fi
  done
}

apply() {
  info "=== Applying dotfiles"

  local files=( $(find $DOTFILES_ROOT -maxdepth 2 -name \*.symlink) )
  for source in "${files[@]}"; do
    local dest="$destdir/.`basename \"${source%.*}\"`"
    # link file
    ln -s $source $dest
    success "linked $source to $dest"
  done
}


#-----------------------------------------------------------------------------
# Initialize
#-----------------------------------------------------------------------------

destdir="$HOME"
DOTFILES_ROOT="$destdir/.dotfiles"
backupdir="$DOTFILES_ROOT-backup/$(date "+%Y%m%d%H%M.%S")"

#-----------------------------------------------------------------------------
# Just do it
#-----------------------------------------------------------------------------

# Is it already installed? Update or download
if [ -d $DOTFILES_ROOT ]; then
  pushd $DOTFILES_ROOT > /dev/null
  update
else
  download
  pushd $DOTFILES_ROOT > /dev/null
fi
echo "working directory: $(pwd)"

# backup before applying
backup
# Apply
apply

#-----------------------------------------------------------------------------
# Finished
#-----------------------------------------------------------------------------
popd > /dev/null
success "Done applying dotfiles"
#exec $SHELL -l<commit_msg>more echos<commit_after>#!/usr/bin/env bash -e
#
echo ''

info () {
  printf "  [ \033[00;34mINFO\033[0m ] $1 \n"
}

success () {
  printf "\r\033[2K  [ \033[00;32mOK\033[0m ] $1\n"
}

fail () {
  printf "\r\033[2K  [\033[0;31mFAIL\033[0m] $1\n"
  echo '' 
  exit
}


update() {
  info "Updating dotfiles"
  git pull origin master
  #git submodule init
  #git submodule update
}

download() {
  info "=== Downloading dotfiles"
  git clone --recursive git://git.merikan.com/dotfiles.git $DOTFILES_ROOT
}

backup() {
  info "=== Backing up local dotfiles to directory $backupdir"
  mkdir -p $backupdir

  local files=( $(find $DOTFILES_ROOT -maxdepth 2 -name \*.symlink) )
  for source in "${files[@]}"; do
    local dest="$destdir/.`basename \"${source%.*}\"`"
    if [ -L "$dest" ] && [ "$dest" -ef $source ]
    then
      info "$(basename $dest) is already a symlink pointing to $source, no need to backup"
      rm $dest
    elif [ -f $dest ] || [ -d $dest ] || [ -L "$dest" ]
    then
      mv $dest $backupdir
      success "moved $dest to $backupdir"
    fi
  done
}

apply() {
  info "=== Applying dotfiles"

  local files=( $(find $DOTFILES_ROOT -maxdepth 2 -name \*.symlink) )
  for source in "${files[@]}"; do
    local dest="$destdir/.`basename \"${source%.*}\"`"
    # link file
    ln -s $source $dest
    success "linked $source to $dest"
  done
}


#-----------------------------------------------------------------------------
# Initialize
#-----------------------------------------------------------------------------

destdir="$HOME"
DOTFILES_ROOT="$destdir/.dotfiles"
backupdir="$DOTFILES_ROOT-backup/$(date "+%Y%m%d%H%M.%S")"

#-----------------------------------------------------------------------------
# Just do it
#-----------------------------------------------------------------------------

# Is it already installed? Update or download
if [ -d $DOTFILES_ROOT ]; then
  pushd $DOTFILES_ROOT > /dev/null
  update
else
  download
  pushd $DOTFILES_ROOT > /dev/null
fi

# backup before applying
backup
# Apply
apply

#-----------------------------------------------------------------------------
# Finished
#-----------------------------------------------------------------------------
popd > /dev/null
success "Done applying dotfiles"
#exec $SHELL -l
{'fraction_non_alphanumeric': 0.33783783783783783, 'fraction_numerical': 0.01961639058413252, 'mean_word_length': 1.5186608122941823, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5279532', 'n_tokens_mistral': 1471, 'n_tokens_neox': 1398, 'n_words': 384}