#!/bin/sh

# A file used to automaticaly copy configs and macros to their appropriate
# location

CONFIGS=~/Source/configs
MACROS=~/Source/macros

# Copy a script over to /usr/local/bin and make it executable. Accepts the full
# path of a file
copy() {
	if [ ! -e $1 ]; then return 1; fi
	sudo cp $1 /usr/local/bin/
	sudo chmod a+x /usr/local/bin/$(basename $1)
	printf "Copied and made executable:  %s\n" $(basename $1)
}

# Exclude files with extensions like .c or .sh that are not executable or
# are incomplete and copy them over
macros() {
	for f in $(find ~/Source/macros -maxdepth 1 -type f -not -name '*.*')
	do
		copy "$f"
	done
}

# Rebuilds selected custom applications
builds() {
	for f in ~/Source/enabled/*
	do
		cd $f
		git -C $f pull
		sudo make clean install
	done
}

vim() {
	sudo cp ~/Source/configs/vimrc.local  /etc/vim/vimrc.local
	# Should copy plugins too
}

bash() {
	cp $CONFIGS/.bashrc ~/.bashrc
	cp $CONFIGS/.profile ~/.profile
}

# Used to configure a new system or reset things for an existing one.
all() {
	ls
}

case $1 in
	configure) copy $MACROS/configure;;
	builds) builds;;
	vim) vim;;
	macros) macros;;
	bash) bash;;
	*) printf "Invalid argument";;
esac