-
Notifications
You must be signed in to change notification settings - Fork 2
/
update_symlinks.sh
executable file
·83 lines (69 loc) · 1.69 KB
/
update_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
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
76
77
78
79
80
81
82
83
#!/bin/bash -
#===============================================================================
#
# FILE: update_symlinks.sh
#
# USAGE: ./update_symlinks.sh
#
# DESCRIPTION: Create symlinks in home
#
# CREATED: 31.07.2011 13:36:05 CEST
#===============================================================================
set -o nounset # Treat unset variables as an error
function realpath() {
# Get absolute path of the script (because of different readlink in macos)
dir=`dirname $1` # The directory where the script is
pushd "$dir" > /dev/null # Go there
callerpath=$PWD # Record the absolute path
popd > /dev/null # Return to previous dir
echo $callerpath
}
usage()
{
cat << EOF
usage: $0 options
This script updates the dotfile symlinks
OPTIONS:
-h Show this message
-f Overwrite existing files
EOF
}
base=false
force=false
while getopts "hf" OPTION
do
case $OPTION in
h)
usage
exit 1
;;
f)
force=true
;;
?)
usage
exit 1
;;
esac
done
if [[ "$force" = 'true' ]]; then
rmopts=
else
rmopts='-i'
fi
cd `dirname $0`
function createLink() {
local dotfile=$1
local suffix=$2
echo $dotfile
base=`basename $dotfile`
rm $rmopts -r $HOME/$suffix$base
ln -v -s $dotfile $HOME/$suffix$base
}
# ensure we're on the base of the dotfiles repo
dotfilespath="$(git rev-parse --show-toplevel)" || exit
for dotfile in ${dotfilespath}/home/* ; do
createLink $dotfile "."
done
createLink $dotfilespath/fish ".config/"
createLink $dotfilespath/bin ""