-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpush_dotfiles.sh
executable file
·75 lines (68 loc) · 1.44 KB
/
push_dotfiles.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/bash
diff_file() {
fname=$1
echo Differences for $fname:;
diff $fname $HOME/$fname
if [ $? -lt 1 ]; then
return 0
fi
return 1
}
diff_dir() {
dname=$1
echo Differences for $dname:;
diff $dname $HOME/$dname | egrep '[<>]'
if [ $? -gt 0 ]; then
return 1
fi
return 0
}
confirm_copy() {
fname=$1
read -p "Copy ${fname} (Y/N) " -n 1
if [[ $REPLY =~ ^[Yy]$ ]]; then
return 1
fi
echo "Skipping copy for ${fname}"
return 0
}
copy_file() {
cp -rp $1 $HOME/$1
}
check_and_copy_file() {
fname=$1
diff_file $fname
if [ $? -gt 0 ]; then
confirm_copy $fname
if [ $? -gt 0 ]; then
set -x
# Build out dir structure if necessary
DIRNAME=$(dirname ~/$fname)
if [ ! -d $DIRNAME ]; then
echo "Directory $DIRNAME does not exist"
mkdir $DIRNAME
else
echo "Directory $DIRNAME exists"
fi
set +x
copy_file $fname
fi
else
echo "No differences, continuing to next file"
fi
}
for i in $(grep -v '^#' filelist); do
# If the entry is a file, we want to check the files underneath for differences
if [ -f $i ]; then
check_and_copy_file $i
elif [ -d $i ]; then
# Find to get the list of files and run check_and_copy_file on each file
for fname in $(find $i -type f); do
check_and_copy_file $fname
done
else
# This isn't a file or directory, so skip it
echo "Not a file or directory. Skipping"
fi
done
echo ''