-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpython.elv
65 lines (55 loc) · 1.51 KB
/
python.elv
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
# Python Virtual Environment Utilites for Elvish
#
# Copyright © 2018
# Ian Woloschin - ian@woloschin.com
#
# License: github.com/iwoloschin/elvish-packages/LICENSE
#
# Activation & deactivation methods for working with Python virtual
# environments in Elvish. Will not allow invalid Virtual
# Environments to be activated.
#
# Install:
# epm:install github.com/iwoloschin/elvish-packages
#
# Use:
# use github.com/iwoloschin/elvish-packages/python
var virtualenv-directory = $E:HOME/.virtualenvs
fn activate {|name|
var virtualenvs = [(ls $virtualenv-directory)]
var error = ?(var confirmed-name = (
each {|virtualenv|
if (eq $name $virtualenv) { put $name }
} $virtualenvs)
)
if (eq $name $confirmed-name) {
set E:VIRTUAL_ENV = $virtualenv-directory/$name
set E:_OLD_VIRTUAL_PATH = $E:PATH
set E:PATH = $E:VIRTUAL_ENV/bin:$E:PATH
if (not-eq $E:PYTHONHOME "") {
set E:_OLD_VIRTUAL_PYTHONHOME = $E:PYTHONHOME
del E:PYTHONHOME
}
} else {
echo 'Virtual Environment "'$name'" not found.'
}
}
set edit:completion:arg-completer[python:activate] = {|@args|
e:ls $virtualenv-directory
}
fn deactivate {
if (not-eq $E:_OLD_VIRTUAL_PATH "") {
set E:PATH = $E:_OLD_VIRTUAL_PATH
del E:_OLD_VIRTUAL_PATH
}
if (not-eq $E:_OLD_VIRTUAL_PYTHONHOME "") {
set E:PYTHONHOME = $E:_OLD_VIRTUAL_PYTHONHOME
del E:_OLD_VIRTUAL_PYTHONHOME
}
if (not-eq $E:VIRTUAL_ENV "") {
del E:VIRTUAL_ENV
}
}
fn list-virtualenvs {
all [(ls $virtualenv-directory)]
}