-
Notifications
You must be signed in to change notification settings - Fork 0
/
vortex.py
55 lines (41 loc) · 1.09 KB
/
vortex.py
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
"""
[vortex.py]
Quick directory aliases.
"""
# for path stuff
import os
# for loading/setting
# vortex map
import pickle
#
# load map if exists
#
# get path to map
PATH_TO_MAP = os.path.join(os.path.expanduser("~"), ".ergo")
PATH_TO_MAP = os.path.join(PATH_TO_MAP, ".pkg-vortex")
try:
# load map
VORTEX_MAP = pickle.load(open(PATH_TO_MAP, "rb"))
except IOError: # when the file may not be read
VORTEX_MAP = {}
def vortex(argc):
"""vortex: Navigate around the filesystem.
Usage:
vortex POINT
vortex set NAME PATH
vortex remove NAME...
vortex list
"""
env = argc.env
if argc.args['POINT']:
env.change_directory(VORTEX_MAP[argc.args['POINT']])
elif argc.args['set']:
VORTEX_MAP.update(kwargs)
pickle.dump(VORTEX_MAP, open(PATH_TO_MAP, "wb"))
elif argc.args['remove']:
for vp in argc.args['NAME']:
del VORTEX_MAP[vp]
pickle.dump(VORTEX_MAP, open(PATH_TO_MAP, "wb"))
elif argc.args['list']:
return [x for x in VORTEX_MAP]
exports = {"vortex": vortex}