-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvirtualenv_bash_for_asdf_python_bashrc
76 lines (66 loc) · 2.24 KB
/
virtualenv_bash_for_asdf_python_bashrc
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
# python virtualenv helpers for asdf
# https://github.com/asdf-vm/asdf/issues/636#issuecomment-674092994
# Other commands adapted from virtualenvwrapper source
# Zsh compatibility has been removed. Just Bash is supported.
export WORKON_HOME=$HOME/.virtualenvs
mkvirtualenv(){
virtualenv -v -p $(asdf where python "$1")/bin/python "$WORKON_HOME"/"$2"
workon "$2"
}
rmvirtualenv(){
rm -rf "$WORKON_HOME"/"$1"
}
workon(){
source "$WORKON_HOME"/"$1"/bin/activate
}
lsvirtualenv(){
(echo $WORKON_HOME/*/bin/activate) 2>/dev/null \
| command \sed "s|$WORKON_HOME/||g" \
| command \sed "s|/bin/activate||g" \
| command \fmt -w 1 \
| (unset GREP_OPTIONS; command \egrep -v '^\*$') 2>/dev/null
}
function virtualenvwrapper_cd {
if [ -n "$BASH" ]
then
builtin \cd "$@"
fi
}
# Verify that the active environment exists
function virtualenvwrapper_verify_active_environment {
if [ ! -n "${VIRTUAL_ENV}" ] || [ ! -d "${VIRTUAL_ENV}" ]
then
echo "ERROR: no virtualenv active, or active virtualenv is missing" >&2
return 1
fi
return 0
}
# Does a ``cd`` to the root of the currently-active virtualenv.
function cdvirtualenv {
# virtualenvwrapper_verify_workon_home || return 1
virtualenvwrapper_verify_active_environment || return 1
virtualenvwrapper_cd $VIRTUAL_ENV/$1
}
# Set up tab completion.
function virtualenvwrapper_setup_tab_completion {
if [ -n "$BASH" ] ; then
_virtualenvs () {
local cur="${COMP_WORDS[COMP_CWORD]}"
COMPREPLY=( $(compgen -W "`lsvirtualenv`" -- ${cur}) )
}
_cdvirtualenv_complete () {
local cur="$2"
COMPREPLY=( $(cdvirtualenv && compgen -d -- "${cur}" ) )
}
# _cdsitepackages_complete () {
# local cur="$2"
# COMPREPLY=( $(cdsitepackages && compgen -d -- "${cur}" ) )
# }
complete -o nospace -F _cdvirtualenv_complete -S/ cdvirtualenv
# complete -o nospace -F _cdsitepackages_complete -S/ cdsitepackages
complete -o default -o nospace -F _virtualenvs workon
complete -o default -o nospace -F _virtualenvs rmvirtualenv
fi
}
virtualenvwrapper_setup_tab_completion
## END: asdf virtualenv-wrapper compatibility