Skip to content

Commit 66d8f5e

Browse files
committed
done ls
1 parent 5f53628 commit 66d8f5e

File tree

1 file changed

+70
-9
lines changed
  • implement-shell-tools/ls

1 file changed

+70
-9
lines changed

implement-shell-tools/ls/ls.py

Lines changed: 70 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import os
22
import argparse
3-
import sys
43

54
parser = argparse.ArgumentParser(
65
prog="ls",
@@ -14,26 +13,88 @@
1413
args = parser.parse_args()
1514

1615
def arguments_proceeding(files):
16+
data_to_proceed = files
17+
18+
if args.a:
19+
data_to_proceed = [f for f in files]
20+
data_to_proceed.sort()
21+
data_to_proceed.insert(0, "..")
22+
data_to_proceed.insert(0, ".")
23+
else:
24+
data_to_proceed = [f for f in files if not f.startswith('.')]
25+
data_to_proceed.sort(key=str.lower)
1726
if args.one:
18-
files.sort()
19-
for f in files:
27+
output = [f for f in data_to_proceed]
28+
for f in output:
2029
print(f)
30+
else:
31+
print(" ".join(data_to_proceed))
32+
33+
34+
35+
36+
37+
38+
39+
40+
41+
42+
43+
44+
2145

22-
if not args.a:
23-
files = [f for f in files if not f.startswith(".")]
2446

2547

48+
49+
50+
51+
# output = files
52+
53+
# # if args.one:
54+
# # files.sort()
55+
# # for f in files:
56+
# # print(f)
57+
58+
# if args.a:
59+
# output = [f for f in files]
60+
# output.sort()
61+
# output.insert(0, "..")
62+
# output.insert(0, ".")
63+
64+
# if args.one:
65+
# output = [f for f in files]
66+
# output.sort()
67+
# for f in output:
68+
# print(f)
69+
70+
71+
# -------
72+
73+
# if args.a:
74+
# output = files # include hidden files
75+
# output.insert(0, "..")
76+
# output.insert(0, ".")
77+
# else:
78+
# # exclude hidden files
79+
# output = [f for f in files if not f.startswith('.')]
80+
81+
# output.sort() # always sort after filtering
82+
83+
# if args.one:
84+
# for f in output:
85+
# print(f)
86+
# else:
87+
# print(" ".join(output))
88+
2689
def path_proceeding(path_argument):
2790
if os.path.isfile(path_argument):
2891
print(path_argument)
2992
elif os.path.isdir(path_argument):
3093
files = os.listdir(path_argument)
3194
arguments_proceeding(files)
32-
# elif not path_argument:
33-
# print("no")
95+
96+
3497

35-
# if not args.path:
36-
# print("no")
3798
path_proceeding(args.path)
3899

39100

0 commit comments

Comments
 (0)