<commit_before>#!/bin/sh

# Repositories from github

ZSH_MODULES="tarruda/zsh-autosuggestions"
VIM_BUNDLES="\
	tpope/vim-fugitive \
	tpope/vim-unimpaired \
	bling/vim-airline \
	ctrlpvim/ctrlp.vim \
	"

# Git repo helper
git_init_dir()
{
	REPOPATH="$1"
	REPODIR="$2"
	if [ -d "$REPODIR" ]; then
		OLDDIR=`pwd`
		cd "$REPODIR"
		git pull
		cd "$OLDDIR"
	else
		git clone "$REPOPATH" "$REPODIR"
	fi
}

git_update_repositories()
{
	TMPD=../.tmp-active
	rm -rf "$TMPD"
	mkdir "$TMPD"
	for d in $@; do
		NAME=`basename "$d"`
		mv "$NAME" "$TMPD"
	done

	OLDDIRS=`find . -type d -maxdepth 1 -mindepth 1`
	echo "Removing (in $PWD): $OLDDIRS..."
	rm -rf .nakal-guard $OLDDIRS

	ACTDIRS=`find "$TMPD" -type d -maxdepth 1 -mindepth 1`
	for d in $ACTDIRS; do
		mv $d .
	done
	rmdir "$TMPD"

	for r in $@; do
		NAME=`basename "$r"`
		git_init_dir "https://github.com/$r" "$NAME"
	done
}

tidy_up_dot_directory()
{
	NAME="$1"
	echo "Inspecting $NAME configuration..."
	if [ -d "$HOME/.$NAME" ]; then
		if [ -f "$HOME/.$NAME/.by-nakal" ]; then
			echo "It's my own $NAME configuration. Removing softlinks..."
			rm -f `find "$HOME/.$NAME" -maxdepth 1 -mindepth 1 -type l`
		else
			echo "ERROR: directory "$HOME/.$NAME" is not familiar to me."
			echo "Please move it away to a safe location!"
			exit 1
		fi
	else
		if [ -e "$HOME/.$NAME" ]; then
			echo "Cannot install in $HOME/.$NAME!"
			exit 1
		fi
	fi
}

echo "[shell-setup] Looking for my installation directory..."
SCRIPT_HOME=`dirname $0`
SCRIPT_HOME=`readlink -f "$SCRIPT_HOME"`
if [ -x "$SCRIPT_HOME/setup.sh" ]; then
	echo "Found myself in $SCRIPT_HOME, good."
else
	echo "Hmm, I cannot find my own directory. Giving up..."
	exit 1
fi

OS=`uname -s`

if [ "$OS" = "FreeBSD" ]; then
	echo "[shell-setup] Checking required packages..."
	pkg info vim git tmux zsh the_silver_searcher > /dev/null
	if [ $? -ne 0 ]; then
		echo "ERROR: Missing packages for bootstrap (shell only)."
		exit 1
	fi
	echo "[shell-setup] Checking recommended packages..."
	pkg info ctags gnupg mutt offlineimap abook lynx > /dev/null
	if [ $? -ne 0 ]; then
		echo "WARNING: Some recommended packages are not installed."
	fi
else
	echo "[shell-setup] WARNING: Skipped checking packages..."
fi

echo "[shell-setup] Checking software capabilities..."
echo "-> Checking git..."
git version | grep -q "git version 2"
if [ $? -ne 0 ]; then
	echo "*** git version 2.x.y is needed."
	exit 1
else
	echo "-> git is ok, good."
fi
echo "-> Checking tmux..."
tmux -V | grep -q "tmux 2."
if [ "$OS" = "FreeBSD" ] && [ $? -ne 0 ]; then
	tmux -V | grep -q "tmux 1.9a"
	if [ $? -ne 0 ]; then
		echo "*** tmux version 2.x (at least 1.9a) is needed."
		exit 1
	fi
fi
echo "-> tmux is ok, good."

echo "-> Checking mutt..."
MUTT_IS_OK=1
mutt -v > /dev/null 2>&1
if [ $? -eq 0 ]; then
	mutt -v | grep -q '+USE_FLOCK'
	if [ $? -ne 0 ]; then
		MUTT_IS_OK=0
		echo "*** FLOCK missing"
	fi
	mutt -v | grep -q '+CRYPT_BACKEND_GPGME'
	if [ $? -ne 0 ]; then
		MUTT_IS_OK=0
		echo "*** GPGME missing"
	fi
	mutt -v | egrep -q 'patch.*\.sidebar\.'
	if [ $? -ne 0 ]; then
		MUTT_IS_OK=0
		echo "*** SIDEBAR patch missing"<commit_msg>setup: Detect sidebar in latest mutt<commit_after>#!/bin/sh

# Repositories from github

ZSH_MODULES="tarruda/zsh-autosuggestions"
VIM_BUNDLES="\
	tpope/vim-fugitive \
	tpope/vim-unimpaired \
	bling/vim-airline \
	ctrlpvim/ctrlp.vim \
	"

# Git repo helper (clone or update a repository)
git_init_dir()
{
	REPOPATH="$1"
	REPODIR="$2"
	if [ -d "$REPODIR" ]; then
		OLDDIR=`pwd`
		cd "$REPODIR"
		git pull
		cd "$OLDDIR"
	else
		git clone "$REPOPATH" "$REPODIR"
	fi
}

git_update_repositories()
{
	# Save repositories that we still need
	TMPD=../.tmp-active
	rm -rf "$TMPD"
	mkdir "$TMPD"
	for d in $@; do
		NAME=`basename "$d"`
		mv "$NAME" "$TMPD"
	done

	# Remove repositories that we don't need anymore
	OLDDIRS=`find . -type d -maxdepth 1 -mindepth 1`
	echo "Removing (in $PWD): $OLDDIRS..."
	rm -rf .nakal-guard $OLDDIRS

	# Move back repositories to update them in place
	ACTDIRS=`find "$TMPD" -type d -maxdepth 1 -mindepth 1`
	for d in $ACTDIRS; do
		mv $d .
	done
	rmdir "$TMPD"

	for r in $@; do
		NAME=`basename "$r"`
		git_init_dir "https://github.com/$r" "$NAME"
	done
}

tidy_up_dot_directory()
{
	NAME="$1"
	echo "Inspecting $NAME configuration..."
	if [ -d "$HOME/.$NAME" ]; then
		if [ -f "$HOME/.$NAME/.by-nakal" ]; then
			echo "It's my own $NAME configuration. Removing softlinks..."
			rm -f `find "$HOME/.$NAME" -maxdepth 1 -mindepth 1 -type l`
		else
			echo "ERROR: directory "$HOME/.$NAME" is not familiar to me."
			echo "Please move it away to a safe location!"
			exit 1
		fi
	else
		if [ -e "$HOME/.$NAME" ]; then
			echo "Cannot install in $HOME/.$NAME!"
			exit 1
		fi
	fi
}

echo "[shell-setup] Looking for my installation directory..."
SCRIPT_HOME=`dirname $0`
SCRIPT_HOME=`readlink -f "$SCRIPT_HOME"`
if [ -x "$SCRIPT_HOME/setup.sh" ]; then
	echo "Found myself in $SCRIPT_HOME, good."
else
	echo "Hmm, I cannot find my own directory. Giving up..."
	exit 1
fi

OS=`uname -s`

if [ "$OS" = "FreeBSD" ]; then
	echo "[shell-setup] Checking required packages..."
	pkg info vim git tmux zsh the_silver_searcher > /dev/null
	if [ $? -ne 0 ]; then
		echo "ERROR: Missing packages for bootstrap (shell only)."
		exit 1
	fi
	echo "[shell-setup] Checking recommended packages..."
	pkg info ctags gnupg mutt offlineimap abook lynx > /dev/null
	if [ $? -ne 0 ]; then
		echo "WARNING: Some recommended packages are not installed."
	fi
else
	echo "[shell-setup] WARNING: Skipped checking packages..."
fi

echo "[shell-setup] Checking software capabilities..."
echo "-> Checking git..."
git version | grep -q "git version 2"
if [ $? -ne 0 ]; then
	echo "*** git version 2.x.y is needed."
	exit 1
else
	echo "-> git is ok, good."
fi
echo "-> Checking tmux..."
tmux -V | grep -q "tmux 2."
if [ "$OS" = "FreeBSD" ] && [ $? -ne 0 ]; then
	tmux -V | grep -q "tmux 1.9a"
	if [ $? -ne 0 ]; then
		echo "*** tmux version 2.x (at least 1.9a) is needed."
		exit 1
	fi
fi
echo "-> tmux is ok, good."

echo "-> Checking mutt..."
MUTT_IS_OK=1
mutt -v > /dev/null 2>&1
if [ $? -eq 0 ]; then
	mutt -v | grep -q '+USE_FLOCK'
	if [ $? -ne 0 ]; then
		MUTT_IS_OK=0
		echo "*** FLOCK missing"
	fi
	mutt -v | grep -q '+CRYPT_BACKEND_GPGME'
	if [ $? -ne 0 ]; then
		MUTT_IS_OK=0
		echo "*** GPGME missing"
	fi
	mutt -v | egrep -q '(patch.*\.sidebar\.|USE_SIDEBAR)'
	if [ $? -ne 0 ]; then
		MUTT_IS_OK=0
		echo "*** SIDEBAR patch missing"
{'fraction_non_alphanumeric': 0.16294919454770757, 'fraction_numerical': 0.012081784386617101, 'mean_word_length': 3.050815558343789, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, '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': '151756', 'n_tokens_mistral': 2805, 'n_tokens_neox': 2588, 'n_words': 830}