-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathsetup
executable file
·163 lines (136 loc) · 3.88 KB
/
setup
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
158
159
160
161
162
163
#!/bin/bash
trap 'setup_error' ERR
setup_error() {
echo
echo "==========================================================="
echo "Something went wrong with setup, it was not able to complete."
echo "Look above for any errors and try to correct them and run again."
echo
echo "If you are unable to fix the error, you can report an issue:"
echo "https://github.com/shift3/laptop/issues"
echo
echo "Please attach the logs printed above this message to help us"
echo "debug the issue."
echo "==========================================================="
exit 1
}
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
append_to_zshrc() {
local text="$1" zshrc
local skip_new_line="${2:-0}"
if [ -w "$HOME/.zshrc.local" ]; then
zshrc="$HOME/.zshrc.local"
else
zshrc="$HOME/.zshrc"
fi
if ! grep -Fqs "$text" "$zshrc"; then
if [ "$skip_new_line" -eq 1 ]; then
printf "%s\\n" "$text" >> "$zshrc"
else
printf "\\n%s\\n" "$text" >> "$zshrc"
fi
fi
}
link_dotfile() {
if [ -L "$HOME/.$1" ] && [ ! -a "HOME/.$1" ]; then
rm "$HOME/.$1"
fi
if [ -e "$HOME/.$1" ] && [ ! -L "$HOME/.$1" ]; then
echo "File already exists at $HOME/.$1 I will back it up for you..."
mv "$HOME/.$1"{,.link.backup}
echo "$HOME/.$1.link.backup created"
fi
echo "Linking $1"
ln -sf "$DIR/$1" "$HOME/.$1"
}
fancy_echo() {
local fmt="$1"; shift
# shellcheck disable=SC2059
printf "\\n$fmt\\n" "$@"
}
load_nvm() {
export NVM_DIR="$HOME/.nvm"
# shellcheck source=/dev/null
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
}
install_nvm() {
if [ ! -d "$HOME/.nvm" ]; then
fancy_echo "Installing Node ..."
mkdir "$HOME/.nvm"
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.1/install.sh | bash
load_nvm
nvm install --lts stable
nvm alias default stable
fi
}
install_os_specific_packages() {
if [[ "$OSTYPE" == "linux-gnu" ]]; then
OS=linux
elif [[ "$OSTYPE" == "darwin"* ]]; then
OS=mac
fi
if [ -f "os/$OS" ]; then
# shellcheck source=/dev/null
source "os/$OS"
fi
}
install_vim_plug() {
if [ ! -f ~/.vim/autoload/plug.vim ]; then
curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
fi
}
vim_up() {
VIM_INSTALL_PHASE=1 vim -u "$HOME"/.vimrc +PlugUpdate +PlugClean! +qa
}
update_shell() {
local shell_path;
shell_path="$(command -v zsh)"
if [ -n "$USER" ]; then
fancy_echo "Changing your shell to zsh ..."
if ! grep "$shell_path" /etc/shells > /dev/null 2>&1 ; then
fancy_echo "Adding '$shell_path' to /etc/shells"
sudo sh -c "echo $shell_path >> /etc/shells"
fi
sudo chsh -s "$shell_path" "$USER"
fi
}
link_dotfile gitconfig
link_dotfile zshrc
link_dotfile psqlrc
link_dotfile gitmessage
link_dotfile gitignore
link_dotfile vimrc
fancy_echo "Installing OS Specific Packages ..."
install_os_specific_packages
install_vim_plug
vim_up
case "$SHELL" in
*/zsh)
fancy_echo "Already using zsh ..."
;;
*)
update_shell
;;
esac
if [ ! -d "$HOME/.nvm" ]; then
fancy_echo "Installing Node ..."
install_nvm
fi
# extended zsh completion
if [ ! -d ~/.zsh/completion ]; then
mkdir -p ~/.zsh
git clone https://github.com/zsh-users/zsh-completions.git ~/.zsh/completion
fi
if [ -f "$HOME/.laptop.user" ]; then
fancy_echo "Running your customizations from ~/.laptop.user..."
# shellcheck disable=SC1090
source "$HOME/.laptop.user"
fi
fancy_echo "===========================================================\\n"
echo "Installation and Dotfiles have been completed successfully!"
echo "If this is your first time running this script, please reboot"
echo "your computer now. Enjoy the setup :)"
fancy_echo "For more information about your new setup see:"
echo "https://github.com/Shift3/laptop/blob/master/README.md"
fancy_echo "==========================================================="