forked from PegasusWang/vim-config
-
Notifications
You must be signed in to change notification settings - Fork 0
/
venv.sh
executable file
·59 lines (54 loc) · 1.69 KB
/
venv.sh
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
#!/usr/bin/env bash
_try_pyenv() {
local name='' src=''
if hash pyenv 2>/dev/null; then
echo '===> pyenv found, searching virtualenvs…'
for name in neovim neovim3 nvim; do
src="$(pyenv prefix "${name}" 2>/dev/null)"
if [ -d "${src}" ]; then
echo "===> pyenv virtualenv found '${name}', upgrading..."
# Symlink virtualenv for easy access
ln -fs "${src}" "${__venv}"
return 0
fi
done
echo "===> skipping pyenv. manual virtualenv isn't found"
echo
echo "Press Ctrl+C and use pyenv to create one yourself (name it 'neovim')"
echo "and run ${0} again. Or press Enter to continue and create a"
echo "virtualenv using: python3 -m venv '${__venv}'"
read -r
else
echo '===> pyenv not found, skipping'
fi
return 1
}
_try_python() {
if ! hash python3 2>/dev/null; then
echo '===> python3 not found, skipping'
return 1
fi
echo "===> python3 found"
[ -d "${__venv}" ] || python3 -m venv "${__venv}"
}
main() {
# Concat a base path for vim cache and virtual environment
local __cache="${XDG_CACHE_HOME:-$HOME/.cache}/vim"
local __venv="${__cache}/venv"
mkdir -p "${__cache}"
if [ -d "${__venv}/neovim2" ]; then
echo -n '===> ERROR: Python 2 has ended its life, '
echo ' only python3 virtualenv is created now.'
echo "Delete '${__venv}' (or backup!) first, and then run ${0} again."
elif _try_pyenv || _try_python; then
# Install Python 3 requirements
"${__venv}/bin/pip" install -U pynvim PyYAML Send2Trash
echo '===> success'
else
echo '===> ERROR: Unable to setup python3 virtualenv.'
echo -e '\nConsider using pyenv with its virtualenv plugin:'
echo '- https://github.com/pyenv/pyenv'
echo '- https://github.com/pyenv/pyenv-virtualenv'
fi
}
main