-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathsetup-symlinks.sh
More file actions
executable file
·46 lines (37 loc) · 958 Bytes
/
Copy pathsetup-symlinks.sh
File metadata and controls
executable file
·46 lines (37 loc) · 958 Bytes
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
#!/bin/bash
#
# This script will create symlinks for all files in LINKS
LINKS="links"
DOTFILES=${PWD}
# validate script working directory is DOTFILES dir
if [ ! -f $DOTFILES/setup-symlinks.sh ]; then
echo "*** ERROR: Make sure to run script in dotfiles dir! ***"
exit
fi
echo "Setting up symlinks:"
while read line; do
if [[ ! $line == \#* ]] && [ -n "$line" ]; then
IFS=","
set -- $line
# dest - the file to override in ~/
# src - the source file in the dotfiles repo
dest=$(echo $1 | sed 's/^ *//g' | sed 's/ *$//g')
dest=${dest/"~"/$HOME}
src=$(echo $2 | sed 's/^ *//g' | sed 's/ *$//g')
src=$DOTFILES$src
# unlink
if [ -L $dest ]; then
unlink $dest
fi
# delete file
if [ -a $dest ]; then
rm -rf $dest
fi
# create dir
mkdir -p -- "$(dirname -- "$dest")"
# create link
ln -sfF $src $dest
# ln -sfF $src $dest
echo "$src -> $dest"
fi
done < $LINKS