-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathcode_dir.py
More file actions
executable file
·63 lines (53 loc) · 1.69 KB
/
code_dir.py
File metadata and controls
executable file
·63 lines (53 loc) · 1.69 KB
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
#!/usr/bin/env python
import os.path
import os
#customer you code dir preifx
print("this command already be discarded")
print("please use command: codedir")
print("quick add 'codedir' by do:")
print("write alias codedir='cd $(find ~/mycode/ /media/zhl/second/code -maxdepth 1 -type d| pick)' to /etc/bash.bashrc")
print("then reopen terminal")
exit()
code_dir_prefix = ['/home/zhl/mycode', '/media/zhl/second/code/']
index = 0
code_dir = {}
for dir_i in code_dir_prefix:
print('Now handle prefix dir: %s' % dir_i)
if (os.path.exists(dir_i)):
for i in os.listdir(dir_i):
file_d = os.path.join(dir_i, i)
if os.path.isdir(file_d):
index = index + 1
code_dir[index] = file_d
if 0 == len(code_dir):
print('Can not find valid dir form code_dir_prefix, pls config it')
exit()
print('-------------------------------------------------------')
print('code inde info:')
for key in code_dir:
print('index: %3s --- [%s]' % (key, code_dir[key]))
system_argc = 'null'
while True:
try:
print('please input the valid index number or code dir')
try:
choose = raw_input(':>')
except (KeyboardInterrupt, EOFError):
print()
exit()
try:
if code_dir.has_key(int(choose)):
system_argc = code_dir[int(choose)]
break
except ValueError:
if choose in code_dir.values():
system_argc = choose
break
except (NameError, SyntaxError):
continue
if 'null' == system_argc:
print('ERR HAPPENED!')
exit
run = 'gnome-terminal --working-directory=%s' % system_argc
print(run)
os.system(run)