Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
4675246
create cat.py file to write our implementation on it
HassanOHOsman Dec 1, 2025
95cfc32
import argparse library
HassanOHOsman Dec 1, 2025
530a234
define program meta data
HassanOHOsman Dec 1, 2025
2fc8e5d
define the -n option
HassanOHOsman Dec 1, 2025
73369ea
define the -b option/flag
HassanOHOsman Dec 1, 2025
3bb2ce9
define the path / file to read from
HassanOHOsman Dec 1, 2025
652c027
read the command line argument during runtime
HassanOHOsman Dec 1, 2025
1f95e09
open the file/path for reading and laod its content
HassanOHOsman Dec 1, 2025
9de5129
added () to resolve buggy code
HassanOHOsman Dec 1, 2025
42b98a5
splitting file content by end of line
HassanOHOsman Dec 1, 2025
f1444f9
after splitting the file content into lines checking if the last line…
HassanOHOsman Dec 1, 2025
4da7430
handle -n flag case
HassanOHOsman Dec 1, 2025
414ebd7
handles the -b option case and it's 2 scenarios
HassanOHOsman Dec 1, 2025
a0daa76
if no flag is selected print the content
HassanOHOsman Dec 1, 2025
cd5256b
corrected the increment to follow python syntax
HassanOHOsman Dec 1, 2025
b1bf214
corrected the logic for when no flag was selected
HassanOHOsman Dec 1, 2025
d0bb387
adding action="store_true" so that the program doesn't expect values …
HassanOHOsman Dec 1, 2025
80e3909
corrected code to follow python syntax
HassanOHOsman Dec 1, 2025
3ce06c4
correct logic for options to further mimic cat tool behaviour
HassanOHOsman Dec 1, 2025
e93d1f9
corrected logic to handle several files/path arguments
HassanOHOsman Dec 1, 2025
f1b5a23
remove js implementation which used to guide me to do the python impl…
HassanOHOsman Dec 1, 2025
f3e7e68
create ls.py file to implement ls tool in python in it
HassanOHOsman Dec 1, 2025
1cbdfd4
add ls implementation in js to guide me when implemening in js
HassanOHOsman Dec 1, 2025
719bf23
define ls program meta data (name, options, paths etc)
HassanOHOsman Dec 1, 2025
2987f4b
read the comman line durign runtime
HassanOHOsman Dec 1, 2025
5b493c9
handling one path with ls
HassanOHOsman Dec 1, 2025
6c8a567
import os library so that you can list files & dir inside a working dir
HassanOHOsman Dec 1, 2025
83e99f3
listing the files & dirs inside the working dir
HassanOHOsman Dec 1, 2025
1d1ac0a
alogic in which the hidden files & dirs are filtered out (not shown) …
HassanOHOsman Dec 1, 2025
9a40bd6
logic added to handle one 1/one optition is added and if not all cont…
HassanOHOsman Dec 1, 2025
1e36528
corrected syntactical errors
HassanOHOsman Dec 1, 2025
01ae017
remove \n when -1 option selected to avoid duplication
HassanOHOsman Dec 1, 2025
7ee60a5
iterating over all_content instead to avoid diplaying hidden files wh…
HassanOHOsman Dec 1, 2025
0a68b74
remove js implementation of ls tool
HassanOHOsman Dec 1, 2025
82424f0
create wc.py file with implementation of wc in js to use as guide whe…
HassanOHOsman Dec 1, 2025
a082839
define program meta data: name, description, options, arguments/paths…
HassanOHOsman Dec 1, 2025
4aad5ab
building counter function
HassanOHOsman Dec 2, 2025
914cfda
added counter function to count words, lines and characters from a pa…
HassanOHOsman Dec 5, 2025
c70d7d9
add skeleton for flags/option cases
HassanOHOsman Dec 5, 2025
d996f5b
corrected bugs in counter function
HassanOHOsman Dec 5, 2025
72c9e8e
updated output message for when a particular option is added by end user
HassanOHOsman Dec 5, 2025
dc375e6
importing os so that we could handle when a path is file vs when a pa…
HassanOHOsman Dec 5, 2025
c4d2796
handling when path is file
HassanOHOsman Dec 5, 2025
d4cd590
flesh out lofic for when path is a dir
HassanOHOsman Dec 5, 2025
76a8647
moving bits of code around and updating var so that in the case of di…
HassanOHOsman Dec 5, 2025
731c907
replace reading files to avoid unnessary memoery usage
HassanOHOsman Jan 14, 2026
baadd85
correct my code to ensuring formatting match the actual act with -n flag
HassanOHOsman Jan 14, 2026
312abeb
handling cases when -a flag is added to ls to show the current and pa…
HassanOHOsman Jan 14, 2026
0b90dbc
handle cases when -a flag not selected
HassanOHOsman Jan 14, 2026
0bd31b0
handle when -1 flag is added and when it's not
HassanOHOsman Jan 14, 2026
a8f7a8d
change 3rd parser.add_argument to allow several paths with default
HassanOHOsman Jan 14, 2026
8a65064
remove reduntant line
HassanOHOsman Jan 14, 2026
a6642bb
improving the quality of code for -a flag code block and adding a fin…
HassanOHOsman Jan 14, 2026
6a5281e
simplify the for loop
HassanOHOsman Jan 14, 2026
683fc0c
adding double spaces for the -one flag to match the format of the act…
HassanOHOsman Jan 14, 2026
b95cf8e
adding sorting method so that it matches the actual ls output order
HassanOHOsman Jan 14, 2026
e3a7ce3
discarding the redantant commented js implementation
HassanOHOsman Jan 14, 2026
82a6800
setting up a helper function that handles reading files, printing sta…
HassanOHOsman Jan 14, 2026
e9f2a54
moving code into the helper function proccess_file
HassanOHOsman Jan 14, 2026
9f5649f
update the default paremeter of the helper function process_file to f…
HassanOHOsman Jan 14, 2026
14fca64
moving code inside helper function process_file
HassanOHOsman Jan 14, 2026
140467f
get rid of repetetive code
HassanOHOsman Jan 14, 2026
088df21
edit code for when path is dir
HassanOHOsman Jan 14, 2026
4b2801f
change parameter to file_path to get rid of bug
HassanOHOsman Jan 14, 2026
6551026
getting rid of all extra }
HassanOHOsman Jan 14, 2026
b1b1669
replace the double spacing with \t to cause the "double spacing" effe…
HassanOHOsman Jan 14, 2026
5158913
change logic to elminate the need for using keyword "global"
HassanOHOsman Jan 14, 2026
92929e0
move total before helper function process_file otherwise error is thr…
HassanOHOsman Jan 15, 2026
85622de
improve the readability to eliminate misinterpration
HassanOHOsman Jan 15, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions implement-shell-tools/cat/cat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import argparse

parser = argparse.ArgumentParser(
prog="display-file-content",
description="Output the content of a file to the terminal",
)

parser.add_argument("-n", help="Number the output lines", action="store_true")
parser.add_argument("-b", help="Number the non-blank output lines", action="store_true")
parser.add_argument("paths", help="The file(s)/path(s) to read from", nargs="+")

args = parser.parse_args()

line_number = 1

for path in args.paths:
with open(path, "r") as f:
for line in f:
line = line.rstrip("\n")
if args.n:
print(f"{line_number:>6} {line}")
line_number += 1
elif args.b:
if line != "":
print(f"{line_number} {line}")
line_number += 1
else:
print(f"{line}")
else:
print(f"{line}")








42 changes: 42 additions & 0 deletions implement-shell-tools/ls/ls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import argparse
import os

parser = argparse.ArgumentParser(
prog="list-files-in-directory",
description="List all files and directories in a directory",
)

parser.add_argument("-1", "--one", dest="one", help="Output one entry per line", action="store_true")
parser.add_argument("-a", help="List all files & directories, including hidden ones", action="store_true")
parser.add_argument("paths", nargs="*", default=["."], help="The file(s) or directories to list")

args = parser.parse_args()

for path in args.paths:
if os.path.isdir(path):
items = os.listdir(path)

if args.a:
items = ['.', '..'] + items
else:
items = [item for item in items if not item.startswith(".")]

items.sort()

for item in items:
if args.one:
print(item)
else:
print(item, end="\t")
if not args.one:
print()
else:
print(path)








76 changes: 76 additions & 0 deletions implement-shell-tools/wc/wc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@

import argparse
import os

parser = argparse.ArgumentParser(
prog="counter",
description="Counts lines, words or characters in a file (or all files) inside a directory",
)

parser.add_argument("-l", "--line", dest="line", help="The number of lines in each file", action="store_true")
parser.add_argument("-w", "--word", dest="word", help="The number of words in each file", action="store_true")
parser.add_argument("-c", "--char", dest="char", help="The number of characters in each file", action="store_true")
parser.add_argument("paths", help="The file(s)/path(s) to read from", nargs="+")

args = parser.parse_args()

total = {'lines': 0, 'words': 0, 'characters': 0, 'files': 0}

def counter(item):
lines = len(item.strip().split("\n"))
words = len(item.split())
characters = len(item)
return {"lines": lines, "words": words, "characters": characters}


def process_file(file_path, total):
with open(file_path, "r") as f:
content = f.read()

stats = counter(content)

if args.line:
print(f"{stats['lines']} {file_path}")
elif args.word:
print(f"{stats['words']} {file_path}")
elif args.char:
print(f"{stats['characters']} {file_path}")
else:
print(f"{stats['lines']} {stats['words']} {stats['characters']} {file_path}")

total['lines'] += stats['lines']
total['words'] += stats['words']
total['characters'] += stats['characters']
total['files'] += 1



for path in args.paths:
if os.path.isfile(path):
process_file(path, total)
elif os.path.isdir(path):
for file in os.listdir(path):
file_path = os.path.join(path, file)
if os.path.isfile(file_path):
process_file(file_path, total)








if total['files'] > 1:
if args.line:
print(f"{total['lines']} total")
elif args.word:
print(f"{total['words']} total")
elif args.char:
print(f"{total['characters']} total")
else:
print(f"{total['lines']} {total['words']} {total['characters']} total")