2014-04-14 20:24:52 -07:00
|
|
|
#!/usr/bin/env bash
|
2014-04-14 20:49:44 -07:00
|
|
|
cd `dirname $BASH_SOURCE` && source bootstrapping.sh
|
|
|
|
DOTFILES_DIRECTORY="$(dotfiles_abspath)/dotfiles"
|
2014-04-14 20:24:52 -07:00
|
|
|
echo $DOTFILES_DIRECTORY
|
2013-09-25 16:38:16 -07:00
|
|
|
|
2013-11-22 10:52:22 -08:00
|
|
|
function symlink_dotfiles() {
|
2014-04-08 05:50:21 -07:00
|
|
|
cd $DOTFILES_DIRECTORY
|
2014-04-09 11:45:52 -07:00
|
|
|
[ -a ~/.dotfiles-backups ] && mv ~/.dotfiles-backups ~/.dotfiles-backups.old
|
2014-04-08 05:50:21 -07:00
|
|
|
mkdir ~/.dotfiles-backups
|
2013-11-22 10:52:22 -08:00
|
|
|
for filename in *; do
|
|
|
|
local link_destination="$HOME/.$filename"
|
2014-04-09 11:45:52 -07:00
|
|
|
local link_target=$(${readlink_command} -f $filename)
|
|
|
|
echo "linking $link_destination to $link_target"
|
|
|
|
# Using only test -e doesn't work here because it will return
|
|
|
|
# false if the destination of the symbolic link at
|
|
|
|
# link_destination does not exist.
|
|
|
|
test -e $link_destination || test -L $link_destination && mv $link_destination ~/.dotfiles-backups
|
|
|
|
ln -si $link_target $link_destination
|
2013-09-25 16:38:16 -07:00
|
|
|
done
|
2014-04-09 11:45:52 -07:00
|
|
|
[ -a ~/.dotfiles-backups.old ] && mv ~/.dotfiles-backups.old ~/.dotfiles-backups/.dotfiles-backups
|
2011-09-05 20:19:31 +02:00
|
|
|
}
|
2013-04-01 02:16:52 +00:00
|
|
|
|
2014-04-14 20:24:52 -07:00
|
|
|
|
|
|
|
function parse_options() {
|
|
|
|
while getopts "f" OPTCHAR; do
|
|
|
|
case $optchar in
|
|
|
|
f)
|
|
|
|
symlink_dotfiles
|
|
|
|
return
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift $((OPTIND-1))
|
|
|
|
|
2014-04-08 05:50:21 -07:00
|
|
|
read -p "Symlinking files from $DOTFILES_DIRECTORY. This may overwrite existing files in your home directory. Do you wish to proceed? (y/n) " -n 1
|
2013-03-17 23:46:42 +01:00
|
|
|
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
2013-11-22 10:52:22 -08:00
|
|
|
symlink_dotfiles
|
2013-03-17 23:46:42 +01:00
|
|
|
fi
|
2014-04-14 20:24:52 -07:00
|
|
|
}
|
2014-04-08 05:50:21 -07:00
|
|
|
|
2014-04-14 20:49:44 -07:00
|
|
|
parse_options
|