-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdot
More file actions
executable file
·127 lines (105 loc) · 2.87 KB
/
Copy pathdot
File metadata and controls
executable file
·127 lines (105 loc) · 2.87 KB
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
#!/usr/bin/env bash
######################################################
## FUNCTIONS
######################################################
switch_to_homebrew_bash() {
if ! fgrep -q '/usr/local/bin/bash' /etc/shells; then
echo '/usr/local/bin/bash' | sudo tee -a /etc/shells;
chsh -s /usr/local/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 `bin/` directory
# It's a `.bin` because I don't like seeing it
e_header "Symlinking custom ~/.bin directory"
symlink "$dotfiles/bin" "$HOME/.bin"
# Link dotfiles
e_header "Symlinking dotfiles"
find home -name '*.sh' | 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"
}
symlink_atom_config() {
dotfiles="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
e_header "Symlinking Atom config"
for file in config.cson init.coffee keymap.cson snippets.cson styles.less; do
symlink "$dotfiles/atom/$file" "$HOME/.atom/$file"
done
}
######################################################
## USAGE
######################################################
usage() {
echo "Usage:" >&2
echo "$0 [--dotfiles] [--atom] [--hosts] [--homebrew-bash]" >&2
echo "" >&2
echo "Options:" >&2
echo " -d | --dotfiles Symlink dotfiles in home/ directory" >&2
echo " -a | --atom Symlink Atom editor config files" >&2
echo " -h | --hosts Create local hosts files and symlink it" >&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;
;;
-a|--atom)
symlink_atom_config
;;
-h|--hosts)
symlink_host_file
;;
--homebrew-bash)
switch_to_homebrew_bash
;;
*)
usage;
exit 100;
;;
esac
done
echo
e_success "Everything's ready"