Skip to content

Commit 4b88392

Browse files
committed
ls: complete
1 parent 9901396 commit 4b88392

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

  • implement-shell-tools/ls

implement-shell-tools/ls/ls.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from os import listdir
33

44
parser = argparse.ArgumentParser(prog="ls", description="List directory contents. Ignore files and directories starting with a '.' by default")
5-
parser.add_argument("-1", help="List one file per line.", action="store_true")
5+
parser.add_argument("-1", dest="one", help="List one file per line.", action="store_true")
66
parser.add_argument("-a", help="Do not ignore hidden files (files with names that start with '.').", action="store_true")
77
parser.add_argument("path", help="The directory path (optional).", default=".", nargs="?")
88

@@ -11,6 +11,7 @@
1111
path = args.path
1212

1313
show_hidden = args.a
14+
one_per_line = args.one
1415

1516
contents = []
1617

@@ -19,5 +20,10 @@
1920
contents.append(f)
2021
if show_hidden == True:
2122
contents.append(f)
22-
23-
print(" ".join(contents))
23+
24+
contents.sort()
25+
26+
if one_per_line == True:
27+
print("\n".join(contents))
28+
else:
29+
print(" ".join(contents))

0 commit comments

Comments
 (0)