-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhrmtools.py
62 lines (56 loc) · 1.74 KB
/
hrmtools.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
56
57
58
59
60
61
62
### External packages:
import os
### Internal packages:
import hrmutils
### Shell functions:
def ls(self, line, stdout = False):
if type(line) != list:
line = line.split()
if type(line) == list and len(line) > 0:
if type(line[0]) == list:
line = sum(line, [])
listed = False
hidden = True
if len(line) == 0:
path = '.'
elif len(line) < 3:
if line[0].startswith('-'): # if command contains flags
if 'l' in line[0]:
listed = True
if 'a' in line[0]:
hidden = False
if len(line) == 1: # if command only contains flags
path = '.'
elif len(line) == 2: # if command also contains path
path = line[1]
else:
path = line[0]
else:
print("please supply one argument with or without flags")
dir_list = hrmutils.list_items(path)
dir_list = sorted(dir_list, key = lambda s: s.lower())
if hidden == True:
dir_list = [i for i in dir_list if i.startswith('.') == False]
if listed == True and stdout == False:
dir_list = hrmutils.colorize_output(dir_list)
for item in dir_list:
print(item)
elif stdout == False:
print(dir_list)
else:
return dir_list
def cat(self, line, stdout = False):
if type(line) != list:
line = line.split()
if type(line[0]) == list:
line = sum(line, [])
out_str = ''
if len(line) == 1:
with open(line[0], 'r') as file:
for line in file:
if stdout == False:
print(line.strip())
out_str = out_str + line
return out_str
def pwd(self, line):
print(os.getcwd())