-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
executable file
·67 lines (49 loc) · 1.5 KB
/
setup.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
#!/bin/bash
# Symlink dotfiles to ~/
# Backs up existing dotfiles to ~/.dotfiles_old/
# Much of this is taken from https://github.com/nicksp/dotfiles
get_os() {
declare -r OS_NAME="$(uname -s)"
local os=""
if [ "$OS_NAME" == "Darwin" ]; then
os="osx"
elif [ "$OS_NAME" == "Linux" ] && [ -e "/etc/lsb-release" ]; then
os="linux"
fi
printf "%s" "$os"
}
dir_backup=~/.dotfiles_old # old dotfiles backup directory
# Create dotfiles_old in homedir
echo -n "Creating $dir_backup for backup of any existing dotfiles in ~/"
mkdir -p $dir_backup
declare -a FILES_TO_SYMLINK=(
'vimrc'
'nethackrc'
'gdbinit'
'bash_profile'
'zshrc'
'gitconfig'
'gitignore_global'
)
# Move any existing dotfiles in homedir to dotfiles_old directory
echo "Moving any existing dotfiles from ~ to $dir_backup"
for i in ${FILES_TO_SYMLINK[@]}; do
mv ~/.${i##*/} $dir_backup
done
# Then create symlinks from the homedir to any files in the ~/dotfiles directory
echo "Creating symlinks to ~/"
for i in ${FILES_TO_SYMLINK[@]}; do
sourceFile="$(pwd)/$i"
targetFile="$HOME/.$(printf "%s" "$i" | sed "s/.*\/\(.*\)/\1/g")"
if [ "$sourceFile" == "$(pwd)/bash_profile" ]; then
sourceFile="$(pwd)/bash_profile_$(get_os)"
fi
if [ ! -e "$targetFile" ]; then
ln -fs $sourceFile $targetFile
fi
if [ "$(readlink "$targetFile")" == "$sourceFile" ]; then
printf "\e[0;32m[✔] $targetFile → $sourceFile\e[0m\n"
else
printf "\e[0;31m[x] $targetFile → $sourceFile\e[0m\n"
fi
done