-
Notifications
You must be signed in to change notification settings - Fork 3
/
dot
executable file
·157 lines (129 loc) · 3.77 KB
/
dot
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#!/usr/bin/env bash
######################################################
## FUNCTIONS
######################################################
switch_to_homebrew_bash() {
if ! fgrep -q '/opt/homebrew/bin/bash' /etc/shells; then
echo '/opt/homebrew/bin/bash' | sudo tee -a /etc/shells;
chsh -s /opt/homebrew/bin/bash;
e_note "Now using bash from Homebrew"
fi;
}
symlink() {
from="$1"
to="$2"
e_arrow "Linking '$from' to '$to'"
rm -f "$to"
ln -s "$from" "$to"
}
susymlink() {
from="$1"
to="$2"
e_arrow "Linking '$from' to '$to'"
sudo rm -f "$to"
sudo ln -s "$from" "$to"
}
symlink_host_file() {
e_header "Linking hosts file"
if [ ! -L "/etc/hosts" ]; then
e_arrow "Saving original file to /etc/hosts.orig"
sudo cp -f /etc/hosts /etc/hosts.orig
fi
dotfiles="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
if [ ! -f "$dotfiles/etc/hosts.local" ]; then
cp "$dotfiles/etc/hosts" "$dotfiles/etc/hosts.local";
fi
susymlink "$dotfiles/etc/hosts.local" "/etc/hosts"
}
symlink_dotfiles() {
dotfiles="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# Link dotfiles
e_header "Symlinking dotfiles"
# Symlink dirs from ./home/folders to ~/.folder
find home -mindepth 1 -type d | while read -r location; do
file="${location##*/}"
symlink "$dotfiles/$location" "$HOME/.$file"
done
# Symlink files
# from ./home/config.sh to ~/.config
# from ./home/config.ext to ~/.config.ext
find home -maxdepth 1 -not -type d | while read -r location; do
file="${location##*/}"
file="${file%.sh}"
symlink "$dotfiles/$location" "$HOME/.$file"
done
# Vim config
e_header "Symlinking VIM config"
symlink "$dotfiles/vim" "$HOME/.vim"
touch "$HOME/.vimlocal"
# .env
e_header "Creating ~/.env file"
if [ ! -f "$HOME/.env" ]; then
e_arrow "Copying '$dotfiles/etc/env.example' to '$HOME/.env'"
e_warning "~/.env is currently empty, add the necessary values"
cp "$dotfiles/etc/env.example" "$HOME/.env";
else
e_note "~/.env already exists"
fi
}
symlink_sublime() {
dotfiles="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
e_header "Symlinking Sublime Text config"
symlink "$dotfiles/macos/Preferences.sublime-settings" "$HOME/Library/Application Support/Sublime Text/Packages/User/Preferences.sublime-settings"
e_note "Make sure you install the theme https://github.com/mauroreisvieira/github-sublime-theme"
}
setup_php() {
dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/dev/php"
(cd $dir && composer install)
e_warning "Add the following line to your php.ini configuration"
echo
echo " auto_prepend_file = $dir/prepend.php"
echo
}
######################################################
## USAGE
######################################################
usage() {
echo "Usage:" >&2
echo "$0 [--dotfiles] [--sublime] [--hosts] [--homebrew-bash] [--php]" >&2
echo "" >&2
echo "Options:" >&2
echo " -d | --dotfiles Symlink dotfiles in home/ directory" >&2
echo " -h | --hosts Create local hosts files and symlink it" >&2
echo " --php Setup php prepended file" >&2
echo " --sublime Symlink Sublime Text preferences" >&2
echo " --homebrew-bash Add bash from homebrew to shell login and switch to it" >&2
}
######################################################
## PARAMETERS
######################################################
if [ $# -eq 0 ]; then
usage;
exit 100;
fi;
for i in "$@"
do
case $i in
-d|--dotfiles)
symlink_dotfiles;
;;
--sublime)
symlink_sublime;
;;
--php)
setup_php;
;;
-h|--hosts)
symlink_host_file
;;
--homebrew-bash)
switch_to_homebrew_bash
;;
*)
usage;
exit 100;
;;
esac
done
echo
e_success "Everything's ready"