-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathlink.sh
executable file
·43 lines (33 loc) · 857 Bytes
/
link.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
#!/bin/bash
echo "Symlinking..."
cat $HOME'/dotfiles/symlinks' | while read line; do
link=$HOME'/'$line
file=$HOME'/dotfiles/'$line
if [[ $line == *" "* ]]; then
link=$HOME'/'$(echo $line | awk '{print $2}')
file=$HOME'/dotfiles/'$(echo $line | awk '{print $1}')
fi
file=$(realpath $file)
doLink=true
doMove=false
if [[ ! -f $link && -d $link && $(readlink -f $link) == $link ]]; then
doMove=true
fi
if [[ -f $link && ! -d $link && $(readlink -f $link) == $link ]]; then
doMove=true
fi
if [[ $(readlink -f $link) == $file ]]; then
doLink=false
fi
if [[ $doLink == true ]]; then
echo $link" not linked, linking now to $file"
fi
if [[ $doMove == true ]]; then
echo "file exists, creating "$link".old"
mv $link $link".old"
fi
if [[ $doLink == true ]]; then
mkdir -p $(dirname $link)
ln -sf $file $link
fi
done