-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
47 lines (39 loc) · 941 Bytes
/
utils.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
import os
from color.conf import color
import socket
def parse_input(line):
"""
delete duplicate inline characters like: ' ', '\t'
:param line: str
:return: str
"""
res = []
length = len(line)
i = 0
skip = [' ', '\t']
while i < length:
if line[i] not in skip:
res.append(line[i])
i += 1
else:
if line[i] == ' ':
res.append(' ')
i += 1
while i < length and line[i] in skip:
i += 1
return ''.join(res)
def parse_args(args):
res = []
sub = []
for item in args:
if item != '|':
sub.append(item)
else:
res.append(sub)
sub = []
if sub:
res.append(sub)
return res
def parse_prompt():
s = '{}@{} {}{}'.format(os.getlogin(), socket.gethostname(), os.getcwd(), ' > ')
return color.prompt(s)