forked from mathiasbynens/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsync.sh
executable file
·48 lines (40 loc) · 1.07 KB
/
sync.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/bash
# cd into the scripts directory.
cd "$(dirname "$0")"
# Get a list of the files to be copied.
exclude_files=(".DS_Store" "README.md" "sync.sh" ".git")
files=$(grep -vxF -f <(printf "%s\n" ${exclude_files[@]}) <(ls -A))
# Determine the sync direction.
echo
echo "Please choose the sync direction:"
select suite in "To homedir" "From homedir";
do
case "$suite" in
"To homedir") syncdir="t";;
"From homedir") syncdir="f";;
*) echo "Invalid option"; exit 0;;
esac
break
done
# Sync the dot files to the home directory.
if [[ $syncdir == "t" ]]; then
# Create a backup of any preexisting dot files.
backupdir="$HOME/dotfiles-backup-$(date +%Y%m%d%H%M%S)"
mkdir $backupdir
for file in ${files[@]}; do
file="$HOME/$file"
[ -e $file ] && cp $file $backupdir
[ -d $file ] && rm -rf $file
done
unset file
# Sync and reload.
rsync -av ${files[@]} $HOME/
source $HOME/.bash_profile
# Sync the dot files from the home directory.
else
for file in ${files[@]}; do
file="$HOME/$file"
[ -e $file ] && cp -r $file .
done
unset file
fi