92 lines
3.5 KiB
Bash
Executable File
92 lines
3.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
#===============================================================================
|
|
#
|
|
# FILE: setup.sh
|
|
# USAGE: ./setup.sh
|
|
# DESCRIPTION: after pulling/cloning dotfiles repo, this script will check/create
|
|
# symlinks for for dotfiles. It checks for the presence of installed
|
|
# software (i.e. won't symlink a dotfile for applications that aren't
|
|
# installed) and will remove links for applications that are no longer
|
|
# installed. Safe to run after every git pull
|
|
# OPTIONS:
|
|
# REQUIREMENTS: This script replies on the 'command' command. Basically, it will run
|
|
# `command -v <dotfile>` and if there is no output, it assumes the app
|
|
# isn't installed. So this won't work for apps that aren't in your $PATH
|
|
# reference: http://www.cyberciti.biz/faq/unix-linux-shell-find-out-posixcommand-exists-or-not/
|
|
# NOTES:
|
|
# AUTHOR: C Hawley
|
|
# CREATED: 2015-10
|
|
# REVISION: Tue 10 Oct 2017 04:37:37 PM EDT
|
|
#
|
|
#===============================================================================
|
|
|
|
set -o nounset # Treat unset variables as an error
|
|
|
|
# specify where your dotfiles live
|
|
dotfiledir="$HOME/dotfiles-vim"
|
|
|
|
# function to handle checking for existings links/files and updating
|
|
link() {
|
|
echo "symlinking ${1}"
|
|
# check for existing symlinks
|
|
if [ -h "${HOME}"/"${1}" ]; then
|
|
echo " - There's already a symlink named ${1}. Diff'ing."
|
|
# If there's an existing sylink, check if it's different than the dotfile
|
|
if [[ $(diff --brief "${HOME}"/"${1}" "${dotfiledir}"/"${1}") ]]; then
|
|
# If the links are different, ask if it should be replaced
|
|
echo " - Old link and new link are different:"
|
|
echo -n " - Replace existing symlink "${1}"? [Y/N] "
|
|
read replace
|
|
if [ "${replace}" = "Y" ] || [ "${replace}" = "y" ]; then
|
|
# If yes, unlink the old file and link the new one and exit
|
|
echo " - Unlinking old file and linking new file"
|
|
unlink "${HOME}"/"${1}"
|
|
ln -s "${dotfiledir}"/"${1}" "${HOME}"/"${1}"
|
|
fi
|
|
else
|
|
# If the link is the same, just exit function
|
|
echo " - Old link and new link are the same."
|
|
fi
|
|
# check for existing file/directory
|
|
elif [ -f "${HOME}"/"${1}" ] || [ -d "${HOME}"/"${1}" ]; then
|
|
echo " - There's already a file or directory named ${1}. Diff'ing."
|
|
if [[ $(diff --brief "${HOME}"/"${1}" "${dotfiledir}"/"${1}") ]]; then
|
|
echo " - Old file/dir and new link are different:"
|
|
echo -n " - Rename "${1}" and create new link? [Y/N] "
|
|
read replace
|
|
if [ "${replace}" = "Y" ] || [ "${replace}" = "y" ]; then
|
|
echo " - Renaming old file/dir and linking new file"
|
|
mv "${HOME}"/"${1}" "${HOME}"/"${1}"_original
|
|
ln -s "${dotfiledir}"/"${1}" "${HOME}"/"${1}"
|
|
fi
|
|
fi
|
|
else
|
|
# If there is no existing file, create one and exit
|
|
echo " - Creating link for ${1}"
|
|
ln -s "${dotfiledir}"/"${1}" "${HOME}"/"${1}"
|
|
fi
|
|
}
|
|
|
|
clear
|
|
|
|
echo "------------------------------------------"
|
|
echo " .vim/.vimrc repo setup script "
|
|
echo "------------------------------------------"
|
|
echo " Setting up symlinks "
|
|
echo "------------------------------------------"
|
|
echo ""
|
|
|
|
# link .vimrc
|
|
#-------------------------------------------------------------------------------
|
|
if [ $(command -v vim) ]; then
|
|
link .vim
|
|
link .vimrc
|
|
else
|
|
echo "... vim not installed"
|
|
fi
|
|
|
|
echo ""
|
|
echo "------------------------------------------"
|
|
echo "Done. "
|
|
echo "------------------------------------------"
|