2014-04-14 14:52:10 -06:00
|
|
|
#!/bin/sh
|
2013-09-30 23:21:02 -06:00
|
|
|
case `uname` in
|
|
|
|
'Darwin')
|
|
|
|
readlink_command='greadlink'
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
readlink_command='readlink'
|
|
|
|
esac
|
2014-04-08 12:34:08 -06:00
|
|
|
DOTFILES_DIRECTORY="$(dirname "${BASH_SOURCE}" | xargs ${readlink_command} -f)/dotfiles"
|
2013-09-25 17:38:16 -06:00
|
|
|
|
2013-11-22 11:52:22 -07:00
|
|
|
function symlink_dotfiles() {
|
2014-04-08 06:50:21 -06:00
|
|
|
cd $DOTFILES_DIRECTORY
|
2014-04-09 12:45:52 -06:00
|
|
|
[ -a ~/.dotfiles-backups ] && mv ~/.dotfiles-backups ~/.dotfiles-backups.old
|
2014-04-08 06:50:21 -06:00
|
|
|
mkdir ~/.dotfiles-backups
|
2013-11-22 11:52:22 -07:00
|
|
|
for filename in *; do
|
|
|
|
local link_destination="$HOME/.$filename"
|
2014-04-09 12:45:52 -06: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 17:38:16 -06:00
|
|
|
done
|
2014-04-09 12:45:52 -06:00
|
|
|
[ -a ~/.dotfiles-backups.old ] && mv ~/.dotfiles-backups.old ~/.dotfiles-backups/.dotfiles-backups
|
2011-09-05 12:19:31 -06:00
|
|
|
}
|
2013-03-31 20:16:52 -06:00
|
|
|
|
2014-04-08 12:34:08 -06:00
|
|
|
if [ "$1" = "--force" -o "$1" = "-f" ]; then
|
2014-04-08 06:50:21 -06:00
|
|
|
symlink_dotfiles
|
2011-09-05 12:19:31 -06:00
|
|
|
else
|
2014-04-08 06:50:21 -06: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 16:46:42 -06:00
|
|
|
echo
|
|
|
|
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
2013-11-22 11:52:22 -07:00
|
|
|
symlink_dotfiles
|
2013-03-17 16:46:42 -06:00
|
|
|
fi
|
2011-09-05 12:19:31 -06:00
|
|
|
fi
|
2014-04-08 06:50:21 -06:00
|
|
|
|
2013-11-22 11:52:22 -07:00
|
|
|
unset symlink_dotfiles
|
2014-04-08 06:50:21 -06:00
|
|
|
unset DOTFILES_DIRECTORY
|