-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsymlinks.sh
executable file
·47 lines (41 loc) · 966 Bytes
/
symlinks.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
#!/bin/bash
readonly dotfiles=".bashrc .bash_profile .emacs.d .gitconfig .lein/profiles.clj .npmrc .tmux.conf"
readonly dotfilesdir="$(cd "$(dirname "$0")" && pwd)"
readonly timestamp="$(date +%s)"
forEachFile () {
for filename in $dotfiles
do
$1 $filename
done
}
removeSymlink () {
local existing=$HOME/$1
if [ -h $existing ]
then
echo "removing symbolic link $existing"
rm $existing
fi
}
backupExisting () {
local existing=$HOME/$1
if [ -e $existing ]
then
local backup=$existing.$timestamp
echo "backing up $existing to $backup"
mv $existing $backup
fi
}
createSymlink () {
local existing=$HOME/$1
local current=$dotfilesdir/$1
echo "symlinking $current to $existing"
ln -s $current $existing
}
if [ "$1" == "-d" ]
then
forEachFile removeSymlink
else
forEachFile removeSymlink
forEachFile backupExisting
forEachFile createSymlink
fi