-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdatedot.sh
executable file
·64 lines (51 loc) · 1.15 KB
/
updatedot.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
#!/bin/bash
# Sav the parent working directory and cd to the directory of the script
DIR=$(pwd)
cd "$( dirname "${BASH_SOURCE[0]}" )"
# Read in the ignore list
IFS=$'\n' read -d '' -r -a dotignores < dotignore
function isignore()
{
for ignore in "${dotignores[@]}"
do
if [ "$1" -ef "$ignore" ]; then
return 0
fi
done
return 1
}
# Traverse over all subdirectories
for d in $(find . -type d -name "*" -not -path "*.git*");
do
# Filter directories in the ignore list
if isignore $d;
then
continue
fi
# If the directory does not exist create it
if [ ! -d "$HOME/$d" ]; then
mkdir "$HOME/$d"
echo "Creating directory: $HOME/$d";
fi
done
# Traverse over all files
for f in $(find . -type f -name "*" -not -path "*.git*");
do
# Filter files in the ignore list
if isignore $f;
then
continue
fi
# trim the './' before each filename
nf=${f:2:${#f}}
# If a file already exists delete it
if [ -f "$HOME/$nf" ]; then
rm $HOME/$f
echo "Deleting $HOME/$nf"
fi
# Create the symbolic link
target="`pwd`/$nf"
ln -s $target $HOME/$f
echo "Creating $target -> $HOME/$nf";
done
cd "$DIR"