2020-01-10 04:45:39 +00:00
|
|
|
#!/bin/bash
|
2020-01-10 06:12:27 +00:00
|
|
|
|
|
|
|
# This script loops through files in this repository, creating symlinks in your
|
|
|
|
# home directory targeting here. It will prompt you to backup regular files and
|
|
|
|
# replace broken symlinks but will ignore good symlinks regardless of their
|
|
|
|
# target.
|
|
|
|
|
2020-01-10 04:45:39 +00:00
|
|
|
DOTFILES="$(pwd)/.*[a-z]"
|
|
|
|
|
2020-01-13 05:09:49 +00:00
|
|
|
for FILE in $DOTFILES; do
|
2020-01-10 04:45:39 +00:00
|
|
|
BASEFILE=$(basename $FILE)
|
2020-01-10 06:12:27 +00:00
|
|
|
NEWLINK=0
|
2020-01-10 04:45:39 +00:00
|
|
|
|
|
|
|
# Exclude the repo's .git folder
|
2020-01-12 06:22:22 +00:00
|
|
|
if [ "$BASEFILE" != ".git" ]; then
|
2020-01-10 04:45:39 +00:00
|
|
|
|
2020-01-10 06:12:27 +00:00
|
|
|
# If basefile is a link
|
2020-01-12 06:22:22 +00:00
|
|
|
if [ -L ~/$BASEFILE ]; then
|
2020-01-10 06:12:27 +00:00
|
|
|
# If basefile is not a file, and therefore is a broken symlink
|
2020-01-12 06:22:22 +00:00
|
|
|
if [ ! -f ~/$BASEFILE ]; then
|
2020-01-13 04:52:35 +00:00
|
|
|
read -p "Press [ENTER] to replace broken symlink ~/$BASEFILE."
|
2020-01-10 06:12:27 +00:00
|
|
|
rm ~/$BASEFILE
|
|
|
|
NEWLINK=1
|
|
|
|
else
|
|
|
|
echo "~/$BASEFILE is already linked."
|
|
|
|
fi
|
2020-01-13 04:52:35 +00:00
|
|
|
# If basefile is a regular file or directory
|
|
|
|
elif [ -f ~/$BASEFILE ] || [ -d ~/$BASEFILE ]; then
|
2020-01-10 06:12:27 +00:00
|
|
|
DATE=$(date '+%Y%m%d%H%M%S')
|
2020-01-13 04:52:35 +00:00
|
|
|
read -p "Press [ENTER] to move ~/$BASEFILE to ~/$BASEFILE-$DATE."
|
2020-01-10 06:12:27 +00:00
|
|
|
mv ~/$BASEFILE ~/$BASEFILE-$DATE
|
|
|
|
NEWLINK=1
|
2020-01-10 04:45:39 +00:00
|
|
|
else
|
2020-01-10 06:12:27 +00:00
|
|
|
echo "Nothing in location ~/$BASEFILE"
|
|
|
|
NEWLINK=1
|
|
|
|
fi
|
2020-01-10 04:45:39 +00:00
|
|
|
|
2020-01-10 06:12:27 +00:00
|
|
|
# Create a new symlink
|
2020-01-13 05:09:49 +00:00
|
|
|
if [ $NEWLINK -eq 1 ]; then
|
2020-01-10 06:12:27 +00:00
|
|
|
echo "Creating new link to $(pwd)/$BASEFILE from" ~
|
|
|
|
ln -s $(pwd)/$BASEFILE ~/$BASEFILE
|
2020-01-10 04:45:39 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
fi
|
|
|
|
done
|
2020-01-12 06:22:22 +00:00
|
|
|
|
|
|
|
. ~/.bashrc
|