-
Notifications
You must be signed in to change notification settings - Fork 9
/
install.sh
executable file
·73 lines (61 loc) · 1.48 KB
/
install.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
#!/usr/bin/env bash
set -e
dotfilespath="$HOME/dotfiles"
FILES=(\
bashrc \
gitconfig \
gitignore \
hyper.js \
tmux.conf \
vim \
vimrc \
zshenv \
zshrc \
)
# The destination path of a dotfile
function dot_path () {
echo "$HOME/.$1"
}
# The destination path of a dotfile
function local_path () {
echo "$HOME/.$1.local"
}
# Links the passed filename to its new location
function link () {
local filename=$1
if [[ ! -e $filename ]]; then
echo "$filename doesn't exist"
return
fi
local path=$(dot_path $filename)
if [[ -f $path ]] && [[ ! -L $path ]]; then
local localpath=$(local_path $filename)
mv $path $localpath
echo "Moved: $path to $localpath"
fi
if [[ -L $path ]]; then
echo "Ok: $path"
elif [[ ! -e $path ]]; then
echo "Linking: $filename to $path"
ln -s $PWD/$filename $path
fi
}
# Loops through and link all files without links
function install_links () {
echo "Linking dotfiles into place:\n"
cd $dotfilespath
for FILE in ${FILES[@]}
do
link $FILE
done
}
install_links
echo "Switching default shell to zsh"
echo "If this fails on MacOS, read https://superuser.com/questions/362372/how-to-change-the-login-shell-on-mac-os-x-from-bash-to-zsh"
chsh -s /bin/zsh
echo "Running module install files:"
find $dotfilespath -mindepth 2 -name 'install.sh' | while read FILE; do
echo $FILE
$FILE
done
echo "Installation complete!"