-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·196 lines (176 loc) · 5.84 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·196 lines (176 loc) · 5.84 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
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#!/bin/bash
GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m' # No Color
function determine_machine() {
sysname="$(uname -s)"
case "${sysname}" in
Linux*) machine=Linux;;
Darwin*) machine=Mac;;
CYGWIN*) machine=Cygwin;;
MINGW*) machine=MinGw;;
*) machine="UNKNOWN:${unameOut}"
esac
echo $machine
}
# to use `has_cmd nvim`, it would check that the name resolves successfully
function has_cmd() {
[ $# -gt 0 ] || return 1
command -v -- "$1" >/dev/null 2>&1
}
# to use `can_run nvim --version`, it would check if the command succeeds
function can_run() {
"$@" >/dev/null 2>&1
}
function has_brew() {
has_cmd brew && can_run brew -v
}
function install_fish() {
if ! has_cmd fish || ! can_run fish -v; then
if has_brew; then
brew install fish
elif [ "$1" = "Linux" ]; then
sudo apt-add-repository ppa:fish-shell/release-4
sudo apt update
sudo apt install fish
fi
fi
./fish/install.sh
}
function install_rustup() {
if ! has_cmd rustup || ! can_run rustup -V; then
echo "\tInstalling..."
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
. "$HOME/.cargo/env"
rustup toolchain install stable
rustup component add rust-analyzer
fi
}
function install_ripgrep() {
if has_brew; then
echo "Installing ripgrep using Homebrew..."
brew install ripgrep
elif has_cmd apt; then
echo "Installing ripgrep using apt..."
sudo apt-get update && sudo apt-get install -y ripgrep
elif has_cmd pacman; then
echo "Installing ripgrep using pacman..."
sudo pacman -S ripgrep
else
echo "Please install ripgrep manually. Visit https://github.com/BurntSushi/ripgrep#installation for instructions."
fi
}
function install_brew() {
if ! has_brew; then
echo "\tInstalling..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
}
function install_gdb() {
if ! has_cmd gdbserver || ! has_cmd gdb; then
if has_brew; then
brew install gdb
elif [ "$1" = "Linux" ]; then
sudo apt-get install gdb gdbserver
fi
fi
./gdb/install.sh
}
function install_clangd() {
if ! has_cmd clangd || ! can_run clangd --version; then
echo "\tInstalling..."
if has_brew; then
brew install llvm
brew link --force llvm
brew install lld
elif [ "$1" = "Linux" ]; then
sudo apt update
sudo apt install clangd
fi
fi
if [ ! -d $HOME/.clang-format ]; then
touch "$HOME/.clang-format";
ln -sf "$HOME"/dotfiles/clangd/.clang-format "$HOME"/.clang-format
echo "Linked .clang-format"
fi
}
function install_tmux() {
if ! has_cmd tmux || ! can_run tmux -V; then
echo "\tInstalling..."
if has_brew; then
brew install tmux
elif [ "$1" = "Linux" ]; then
sudo apt install tmux
fi
fi
if [ ! -d $HOME/.tmux.conf ]; then
touch "$HOME/.tmux.conf";
ln -sf "$HOME"/dotfiles/tmux/.tmux.conf "$HOME"/.tmux.conf
echo "Linked .tmux.conf"
fi
}
function install_neovim() {
if ! has_cmd nvim || ! can_run nvim --version; then
echo "\tInstalling..."
if has_brew; then
brew install neovim
elif [ "$1" = "Linux" ]; then
# _Sometimes_ apt is prohibited to use on work, rely on yum in that cases
if has_cmd apt-get && can_run apt-get --version; then
echo "\t\tTrying out apt-get..."
sudo apt-get install neovim
elif has_cmd yum && can_run yum version; then
echo "\t\tTrying out yum..."
yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
yum install -y neovim python3-neovim
fi
# Checking if the nvim was successfully installed (_sometimes_ certain security restrictions doesn't allow installing it)
if ! has_cmd nvim || ! can_run nvim --version; then
echo "\t\t${RED}PUT YOUR SEATBELT ON! ${NC}Downloading pre-built archive..."
# Last resort: downloading neovim from pre-built archive
curl -LO https://github.com/neovim/neovim/releases/latest/download/nvim-linux64.tar.gz
sudo rm -rf /opt/nvim
sudo tar -C /opt -xzf nvim-linux64.tar.gz
export PATH="$PATH:/opt/nvim-linux64/bin"
fi
fi
# Install packer
git clone --depth 1 https://github.com/wbthomason/packer.nvim\
~/.local/share/nvim/site/pack/packer/start/packer.nvim
# Symlink neovim config
./nvim/install.sh
# Install packer dependencies
nvim --headless -c 'autocmd User PackerComplete quitall' -c 'PackerSync'
else
# Symlink neovim config
./nvim/install.sh
# Install packer dependencies
nvim --headless -c 'autocmd User PackerComplete quitall' -c 'PackerSync'
fi
}
function main() {
machine=$(determine_machine)
if [[ "$machine" != "Mac" && "$machine" != "Linux" ]]; then
echo "${RED}The script is not configured for the machine of type ${machine}${NC}"
return 1
fi
echo "Setting up your ${machine}..."
echo "🍺 HomeBrew setup..."
install_brew
echo "🍫 tmux setup..."
install_tmux "$machine"
echo "🎵 clangd setup..."
install_clangd
echo "🐞🐠 gdb setup..."
install_gdb
echo "🪦 ripgrep setup..."
install_ripgrep
echo "🦀 rust setup..."
install_rustup
echo "✌️ neovim setup..."
install_neovim "$machine"
echo "🐟 fish setup..."
install_fish "$machine"
echo "${GREEN}Setup finished!${NC}"
}
main