-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsetup-neovim
executable file
·190 lines (157 loc) · 4.04 KB
/
setup-neovim
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
#!/usr/bin/env bash
set -euo pipefail
command_exists() {
type "${1}" >/dev/null 2>&1
}
is_darwin() {
[[ $OSTYPE = darwin* ]]
}
is_linux() {
[[ $OSTYPE = linux* ]]
}
declare setup_method=""
declare source_clean=""
declare dev_mode=""
while (( "$#" )); do
case "$1" in
--appimage)
setup_method="appimage"
shift;;
--brew)
setup_method="brew"
shift;;
--source)
setup_method="source"
shift;;
--clean)
source_clean="true"
shift;;
--dev)
dev_mode="true"
setup_method="source"
shift;;
esac
done
if [[ -z "${setup_method}" ]]; then
if is_darwin; then
setup_method="brew"
elif is_linux; then
setup_method="source"
else
echo "Unknown OS!"
exit 1
fi
fi
get_latest_reposiotry() {
local repo_uri="${1}"
local repo_dir="${2}"
echo "Repository URI: ${repo_uri}"
if [[ ! -d "${repo_dir}" ]]; then
echo "Cloning repository..."
mkdir -p "$(dirname "${repo_dir}")"
git clone --quiet --recursive --depth 10 "${repo_uri}" "${repo_dir}"
pushd "${repo_dir}" >/dev/null
else
echo "Pulling latest commits..."
pushd "${repo_dir}" >/dev/null
git pull
git submodule update --init
fi
popd >/dev/null
}
setup_apt_packages() {
local apt_bin="apt"
if type apt-fast >/dev/null 2>&1; then
apt_bin="apt-fast"
fi
echo "Installing packages: $*"
sudo $apt_bin install -qq --yes "$@"
}
setup_brew_packages() {
echo "Installing packages: $*"
printf 'brew "%s"\n' $* | brew bundle --no-lock --file=-
}
link_binary() {
local binary_name="${1}"
echo "Setting up binary: ${binary_name}"
sudo ln -nsf "${HOME}/.local/bin/${binary_name}" "/usr/local/bin/${binary_name}"
}
setup_neovim_brew() {
echo "Installing LuaJIT..."
if test -z "$(brew list | grep luajit)"; then
echo brew install --HEAD luajit
else
brew reinstall luajit
fi
echo "Installing NeoVim..."
if test -z "$(brew list | grep neovim)"; then
echo brew install --HEAD neovim
else
brew reinstall neovim
fi
}
setup_neovim_appimage() {
cd /tmp
echo "Installing NeoVim..."
local -r _neovim_version=${1:-"nightly"}
local -r _neovim_url="https://github.com/neovim/neovim/releases/download/${_neovim_version}/nvim.appimage"
local -r _neovim_dir="/opt/neovim"
echo "Downloading AppImage..."
wget --continue --quiet --show-progress --timestamping "${_neovim_url}" -O nvim.appimage
chmod u+x nvim.appimage
echo "Installation Directory: ${_neovim_dir}"
sudo mkdir -p ${_neovim_dir}
if [[ -f "${_neovim_dir}/nvim.appimage" ]]; then
sudo mv ${_neovim_dir}/nvim.appimage ${_neovim_dir}/nvim.appimage.old
fi
sudo mv nvim.appimage ${_neovim_dir}/nvim.appimage
echo "Setting up NeoVim binary: nvim"
sudo ln -nsf ${_neovim_dir}/nvim.appimage /usr/local/bin/nvim
}
setup_neovim_source() {
if [[ "${dev_mode}" != "true" ]]; then
get_latest_reposiotry "https://github.com/neovim/neovim" "${HOME}/Dev/github/neovim/neovim"
fi
pushd "${HOME}/Dev/github/neovim/neovim" >/dev/null
if [[ "${dev_mode}" != "true" ]]; then
echo "Installing dependencies..."
if is_darwin; then
setup_brew_packages ninja libtool automake cmake pkg-config gettext curl
fi
if is_linux; then
setup_apt_packages ninja-build gettext libtool libtool-bin autoconf automake cmake g++ pkg-config unzip curl
fi
fi
echo "Running build..."
if [[ -n "${source_clean}" ]]; then
make distclean
fi
make CMAKE_BUILD_TYPE=Release CMAKE_INSTALL_PREFIX="${HOME}/.local" cmake
echo "Installing..."
make install
if [[ "${dev_mode}" != "true" ]]; then
link_binary "nvim"
fi
}
case "${setup_method}" in
appimage)
setup_neovim_appimage "${2:-nightly}"
;;
brew)
setup_neovim_brew
;;
source)
setup_neovim_source
;;
*)
echo "Unknown setup method!"
exit 1;;
esac
if [[ "${dev_mode}" != "true" ]]; then
echo "Creating binary link: vim -> nvim"
ln -nsf "$(command -v nvim)" "${HOME}/.local/bin/vim"
if command_exists setup-neovim-providers; then
setup-neovim-providers
fi
fi
echo "Done!"