From acf2628aa9b497c341a6db68d4a8a5da3e15cb27 Mon Sep 17 00:00:00 2001 From: "[Elhadj Abdoul Diallo]" <[elhhabdouldiallo@gmail.com]> Date: Wed, 5 Mar 2025 16:00:46 +0000 Subject: [PATCH 01/40] Add initial implementation of ls tool to read and print file content --- implement-shell-tools/ls/ls.py | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 implement-shell-tools/ls/ls.py diff --git a/implement-shell-tools/ls/ls.py b/implement-shell-tools/ls/ls.py new file mode 100644 index 0000000..d11e4f2 --- /dev/null +++ b/implement-shell-tools/ls/ls.py @@ -0,0 +1,8 @@ + +import sys + +args = sys.argv[1:] + +with open(args[0], 'r') as f: + content = f.read() +print(content) \ No newline at end of file From f8f1ca8b818c42cbea93a5240029adb4e4719e5d Mon Sep 17 00:00:00 2001 From: "[Elhadj Abdoul Diallo]" <[elhhabdouldiallo@gmail.com]> Date: Wed, 5 Mar 2025 16:02:33 +0000 Subject: [PATCH 02/40] Refactor ls tool to encapsulate file reading and printing in a function --- implement-shell-tools/ls/ls.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/implement-shell-tools/ls/ls.py b/implement-shell-tools/ls/ls.py index d11e4f2..49a7852 100644 --- a/implement-shell-tools/ls/ls.py +++ b/implement-shell-tools/ls/ls.py @@ -3,6 +3,10 @@ args = sys.argv[1:] -with open(args[0], 'r') as f: - content = f.read() -print(content) \ No newline at end of file + +def read_and_print_file_content(): + with open(args[0], 'r') as f: + content = f.read() + print(content) + +read_and_print_file_content() \ No newline at end of file From 4b0c2dcfff266371f55d93805cd09e06243d2ecc Mon Sep 17 00:00:00 2001 From: "[Elhadj Abdoul Diallo]" <[elhhabdouldiallo@gmail.com]> Date: Wed, 5 Mar 2025 20:17:29 +0000 Subject: [PATCH 03/40] Remove ls tool implementation and related file reading logic --- implement-shell-tools/ls/ls.py | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/implement-shell-tools/ls/ls.py b/implement-shell-tools/ls/ls.py index 49a7852..e69de29 100644 --- a/implement-shell-tools/ls/ls.py +++ b/implement-shell-tools/ls/ls.py @@ -1,12 +0,0 @@ - -import sys - -args = sys.argv[1:] - - -def read_and_print_file_content(): - with open(args[0], 'r') as f: - content = f.read() - print(content) - -read_and_print_file_content() \ No newline at end of file From 5050c26228c49656a0c4dc860958da0c2ca7a4cb Mon Sep 17 00:00:00 2001 From: "[Elhadj Abdoul Diallo]" <[elhhabdouldiallo@gmail.com]> Date: Wed, 5 Mar 2025 20:30:11 +0000 Subject: [PATCH 04/40] Add initial implementation of cat tool to read and print file content --- implement-shell-tools/cat/cat.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 implement-shell-tools/cat/cat.py diff --git a/implement-shell-tools/cat/cat.py b/implement-shell-tools/cat/cat.py new file mode 100644 index 0000000..56e42ab --- /dev/null +++ b/implement-shell-tools/cat/cat.py @@ -0,0 +1,11 @@ +import sys + +args = sys.argv[1:] + +def read_and_print_file_content(file_path): + with open(file_path, 'r') as f: + content = f.read() + print(content) + +contents = map(read_and_print_file_content, args) +print(list(contents)) \ No newline at end of file From 59fb74ad16a849dd7bad3531008405c7abb5312c Mon Sep 17 00:00:00 2001 From: "[Elhadj Abdoul Diallo]" <[elhhabdouldiallo@gmail.com]> Date: Wed, 5 Mar 2025 20:32:55 +0000 Subject: [PATCH 05/40] Refactor cat tool to return file content and print it in a loop --- implement-shell-tools/cat/cat.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/implement-shell-tools/cat/cat.py b/implement-shell-tools/cat/cat.py index 56e42ab..5f22611 100644 --- a/implement-shell-tools/cat/cat.py +++ b/implement-shell-tools/cat/cat.py @@ -5,7 +5,9 @@ def read_and_print_file_content(file_path): with open(file_path, 'r') as f: content = f.read() - print(content) - + return content contents = map(read_and_print_file_content, args) -print(list(contents)) \ No newline at end of file + +for content in contents: + if content is not None: + print(content) \ No newline at end of file From 4fa86d0ab99d11a97b4b9b0ef52ecd4ca2dadb6b Mon Sep 17 00:00:00 2001 From: "[Elhadj Abdoul Diallo]" <[elhhabdouldiallo@gmail.com]> Date: Wed, 5 Mar 2025 21:12:23 +0000 Subject: [PATCH 06/40] Refactor cat tool to use argparse for command-line argument parsing --- implement-shell-tools/cat/cat.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/implement-shell-tools/cat/cat.py b/implement-shell-tools/cat/cat.py index 5f22611..a047816 100644 --- a/implement-shell-tools/cat/cat.py +++ b/implement-shell-tools/cat/cat.py @@ -1,13 +1,22 @@ -import sys +import argparse -args = sys.argv[1:] +parser = argparse.ArgumentParser( + prog="cat program implementation", + description="Implements the cat program", +) + +parser.add_argument("-n", "--number", help="The number for the line") +parser.add_argument("paths", nargs='+', help="The files to search") + + +args = parser.parse_args() def read_and_print_file_content(file_path): with open(file_path, 'r') as f: content = f.read() return content -contents = map(read_and_print_file_content, args) +contents = map(read_and_print_file_content, args.paths) for content in contents: if content is not None: - print(content) \ No newline at end of file + print(content) From aa0ed1dc259f6449d5218aaeaa3c9e10340beb3e Mon Sep 17 00:00:00 2001 From: "[Elhadj Abdoul Diallo]" <[elhhabdouldiallo@gmail.com]> Date: Thu, 6 Mar 2025 10:03:52 +0000 Subject: [PATCH 07/40] add option n for numbering lines for only one file passed as command line argument --- implement-shell-tools/cat/cat.py | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/implement-shell-tools/cat/cat.py b/implement-shell-tools/cat/cat.py index a047816..cedc4ac 100644 --- a/implement-shell-tools/cat/cat.py +++ b/implement-shell-tools/cat/cat.py @@ -5,18 +5,34 @@ description="Implements the cat program", ) -parser.add_argument("-n", "--number", help="The number for the line") -parser.add_argument("paths", nargs='+', help="The files to search") +parser.add_argument("-n", "--number", action="store_true", help="Number the output lines, starting at 1.") +parser.add_argument("path", help="The files to search") args = parser.parse_args() +number_lines = args.number +print(args) +print(number_lines) -def read_and_print_file_content(file_path): + +def read_and_print_file_content(file_path, number_lines): + count = 0 with open(file_path, 'r') as f: content = f.read() - return content -contents = map(read_and_print_file_content, args.paths) + lines = content.split('\n') + for line in lines: + if number_lines: + count+=1 + print(count, line) + else: + print(line) + + + + +read_and_print_file_content(args.path, number_lines) +# contents = map(read_and_print_file_content, args.paths) -for content in contents: - if content is not None: - print(content) +# for content in contents: +# if content is not None: +# print(content) From 946e2446fde3f2a720ab452c9b17f79ce8c34131 Mon Sep 17 00:00:00 2001 From: "[Elhadj Abdoul Diallo]" <[elhhabdouldiallo@gmail.com]> Date: Thu, 6 Mar 2025 10:24:43 +0000 Subject: [PATCH 08/40] Refactor cat tool to extract content lines into a separate function --- implement-shell-tools/cat/cat.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/implement-shell-tools/cat/cat.py b/implement-shell-tools/cat/cat.py index cedc4ac..a0842f3 100644 --- a/implement-shell-tools/cat/cat.py +++ b/implement-shell-tools/cat/cat.py @@ -11,15 +11,15 @@ args = parser.parse_args() number_lines = args.number -print(args) -print(number_lines) +# print(args) +# print(number_lines) def read_and_print_file_content(file_path, number_lines): count = 0 with open(file_path, 'r') as f: content = f.read() - lines = content.split('\n') + lines = extractContentLines(content) for line in lines: if number_lines: count+=1 @@ -30,7 +30,15 @@ def read_and_print_file_content(file_path, number_lines): + +def extractContentLines(content): + lines = content.split('\n') + if lines and lines[-1] == '': + lines = lines[:-1] + return lines + read_and_print_file_content(args.path, number_lines) + # contents = map(read_and_print_file_content, args.paths) # for content in contents: From 2b59eddc20caa976baa8df3ff211e737b8f77c24 Mon Sep 17 00:00:00 2001 From: "[Elhadj Abdoul Diallo]" <[elhhabdouldiallo@gmail.com]> Date: Thu, 6 Mar 2025 10:27:04 +0000 Subject: [PATCH 09/40] Refactor cat tool to implement output_lines_with_numbers function for line numbering --- implement-shell-tools/cat/cat.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/implement-shell-tools/cat/cat.py b/implement-shell-tools/cat/cat.py index a0842f3..6ee81c3 100644 --- a/implement-shell-tools/cat/cat.py +++ b/implement-shell-tools/cat/cat.py @@ -11,15 +11,16 @@ args = parser.parse_args() number_lines = args.number -# print(args) -# print(number_lines) - def read_and_print_file_content(file_path, number_lines): count = 0 with open(file_path, 'r') as f: content = f.read() lines = extractContentLines(content) + output_lines_with_numbers(number_lines, count, lines) + + +def output_lines_with_numbers(number_lines, count, lines): for line in lines: if number_lines: count+=1 From 12ab72a22c2fd9f7646cce9caa0d4307a6ab6295 Mon Sep 17 00:00:00 2001 From: "[Elhadj Abdoul Diallo]" <[elhhabdouldiallo@gmail.com]> Date: Thu, 6 Mar 2025 10:44:34 +0000 Subject: [PATCH 10/40] Refactor cat tool to support multiple file inputs and streamline line numbering logic --- implement-shell-tools/cat/cat.py | 44 ++++++++++++++------------------ 1 file changed, 19 insertions(+), 25 deletions(-) diff --git a/implement-shell-tools/cat/cat.py b/implement-shell-tools/cat/cat.py index 6ee81c3..ef0e7bb 100644 --- a/implement-shell-tools/cat/cat.py +++ b/implement-shell-tools/cat/cat.py @@ -6,42 +6,36 @@ ) parser.add_argument("-n", "--number", action="store_true", help="Number the output lines, starting at 1.") -parser.add_argument("path", help="The files to search") - +parser.add_argument("paths", nargs='+', help="The files to search") args = parser.parse_args() number_lines = args.number -def read_and_print_file_content(file_path, number_lines): - count = 0 +def read_file_content(file_path): with open(file_path, 'r') as f: - content = f.read() - lines = extractContentLines(content) - output_lines_with_numbers(number_lines, count, lines) + return f.read() +def extract_content_lines(content): + lines = content.split('\n') + if lines and lines[-1] == '': + lines = lines[:-1] + return lines -def output_lines_with_numbers(number_lines, count, lines): +def output_lines_with_numbers(number_lines, lines): + count = 0 for line in lines: if number_lines: - count+=1 + count += 1 print(count, line) else: print(line) - - - - - -def extractContentLines(content): - lines = content.split('\n') - if lines and lines[-1] == '': - lines = lines[:-1] - return lines - -read_and_print_file_content(args.path, number_lines) -# contents = map(read_and_print_file_content, args.paths) +# Read contents of all files into a list +all_lines = [] +for path in args.paths: + content = read_file_content(path) + lines = extract_content_lines(content) + all_lines.extend(lines) -# for content in contents: -# if content is not None: -# print(content) +# Output lines with or without numbering +output_lines_with_numbers(number_lines, all_lines) From b61e4d11b3dec398fa9be8d411c61f747e3bfdc9 Mon Sep 17 00:00:00 2001 From: "[Elhadj Abdoul Diallo]" <[elhhabdouldiallo@gmail.com]> Date: Thu, 6 Mar 2025 10:54:00 +0000 Subject: [PATCH 11/40] Add option to number non-empty lines in cat tool --- implement-shell-tools/cat/cat.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/implement-shell-tools/cat/cat.py b/implement-shell-tools/cat/cat.py index ef0e7bb..1881221 100644 --- a/implement-shell-tools/cat/cat.py +++ b/implement-shell-tools/cat/cat.py @@ -6,10 +6,10 @@ ) parser.add_argument("-n", "--number", action="store_true", help="Number the output lines, starting at 1.") +parser.add_argument("-b", "--number2", action="store_true", help="Number the output of non-empty lines, starting at 1.") parser.add_argument("paths", nargs='+', help="The files to search") args = parser.parse_args() -number_lines = args.number def read_file_content(file_path): with open(file_path, 'r') as f: @@ -21,12 +21,17 @@ def extract_content_lines(content): lines = lines[:-1] return lines -def output_lines_with_numbers(number_lines, lines): +def output_lines_with_numbers(lines): count = 0 + number_lines = args.number + number_non_empty_lines = args.number2 for line in lines: if number_lines: count += 1 print(count, line) + elif(number_non_empty_lines) and line != '': + count += 1 + print(count, line) else: print(line) @@ -38,4 +43,4 @@ def output_lines_with_numbers(number_lines, lines): all_lines.extend(lines) # Output lines with or without numbering -output_lines_with_numbers(number_lines, all_lines) +output_lines_with_numbers(all_lines) From b9086885b4abc342f05b60d1855d2c58b2e438dd Mon Sep 17 00:00:00 2001 From: "[Elhadj Abdoul Diallo]" <[elhhabdouldiallo@gmail.com]> Date: Thu, 6 Mar 2025 11:36:27 +0000 Subject: [PATCH 12/40] Implement basic ls command with directory listing functionality --- implement-shell-tools/ls/ls.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/implement-shell-tools/ls/ls.py b/implement-shell-tools/ls/ls.py index e69de29..afc4750 100644 --- a/implement-shell-tools/ls/ls.py +++ b/implement-shell-tools/ls/ls.py @@ -0,0 +1,21 @@ +import argparse +import os + + +parser = argparse.ArgumentParser( + prog="The ls program", + description="Implements the ls program" +) +parser.add_argument('dir', nargs='?', type=str, help="Path to the directory to list", default='.') +parser.add_argument("-1", "--one", action="store_true", help="list the directory files one per line") + +args = parser.parse_args() +print(args) + +def read_dir(): + dir = args.dir + contents = os.listdir(dir) + for content in contents: + print(content) + +read_dir() \ No newline at end of file From 2c493bf648933bca699d3ada463118decf30c156 Mon Sep 17 00:00:00 2001 From: "[Elhadj Abdoul Diallo]" <[elhhabdouldiallo@gmail.com]> Date: Thu, 6 Mar 2025 11:53:42 +0000 Subject: [PATCH 13/40] Update ls command to print directory contents in a single line --- implement-shell-tools/ls/ls.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/implement-shell-tools/ls/ls.py b/implement-shell-tools/ls/ls.py index afc4750..9c2021a 100644 --- a/implement-shell-tools/ls/ls.py +++ b/implement-shell-tools/ls/ls.py @@ -14,8 +14,8 @@ def read_dir(): dir = args.dir - contents = os.listdir(dir) - for content in contents: - print(content) + contents = ' '.join(os.listdir(dir)) + print(contents) + read_dir() \ No newline at end of file From f83037b8b96a9e11aff7dc1d6621f4e1fff86a6d Mon Sep 17 00:00:00 2001 From: "[Elhadj Abdoul Diallo]" <[elhhabdouldiallo@gmail.com]> Date: Thu, 6 Mar 2025 12:03:02 +0000 Subject: [PATCH 14/40] Enhance ls command to support listing files one per line with -1 option --- implement-shell-tools/ls/ls.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/implement-shell-tools/ls/ls.py b/implement-shell-tools/ls/ls.py index 9c2021a..22956dd 100644 --- a/implement-shell-tools/ls/ls.py +++ b/implement-shell-tools/ls/ls.py @@ -10,12 +10,16 @@ parser.add_argument("-1", "--one", action="store_true", help="list the directory files one per line") args = parser.parse_args() -print(args) def read_dir(): + one = args.one dir = args.dir - contents = ' '.join(os.listdir(dir)) - print(contents) + contents = os.listdir(dir) + for content in contents: + if one: + print(content) + if not one: + print(' '.join(contents)) read_dir() \ No newline at end of file From 8c55ba35b7c19ef6d3899cf095ea6b50d9f69205 Mon Sep 17 00:00:00 2001 From: "[Elhadj Abdoul Diallo]" <[elhhabdouldiallo@gmail.com]> Date: Thu, 6 Mar 2025 12:30:51 +0000 Subject: [PATCH 15/40] Filter out hidden files in ls command output --- implement-shell-tools/ls/ls.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/implement-shell-tools/ls/ls.py b/implement-shell-tools/ls/ls.py index 22956dd..402e7bf 100644 --- a/implement-shell-tools/ls/ls.py +++ b/implement-shell-tools/ls/ls.py @@ -11,15 +11,20 @@ args = parser.parse_args() +def does_not_start_with_do(filename): + return not filename.startswith('.') + def read_dir(): one = args.one dir = args.dir - contents = os.listdir(dir) - for content in contents: + files = os.listdir(dir) + non_hidden_files_or_dirs = list(filter(does_not_start_with_do,files )) + print(non_hidden_files_or_dirs, 'filtered elements') + for content in files: if one: print(content) if not one: - print(' '.join(contents)) + print(' '.join(files)) read_dir() \ No newline at end of file From 92ce714615087bc36e90f1acd1475deb296cbada Mon Sep 17 00:00:00 2001 From: "[Elhadj Abdoul Diallo]" <[elhhabdouldiallo@gmail.com]> Date: Thu, 6 Mar 2025 12:48:48 +0000 Subject: [PATCH 16/40] Add option to list hidden files in ls command --- implement-shell-tools/ls/ls.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/implement-shell-tools/ls/ls.py b/implement-shell-tools/ls/ls.py index 402e7bf..564adb7 100644 --- a/implement-shell-tools/ls/ls.py +++ b/implement-shell-tools/ls/ls.py @@ -9,6 +9,8 @@ parser.add_argument('dir', nargs='?', type=str, help="Path to the directory to list", default='.') parser.add_argument("-1", "--one", action="store_true", help="list the directory files one per line") +parser.add_argument("-a", "--hidden_files", action="store_true", help="list the directory files one per line") + args = parser.parse_args() def does_not_start_with_do(filename): @@ -16,15 +18,20 @@ def does_not_start_with_do(filename): def read_dir(): one = args.one + hidden_files = args.hidden_files dir = args.dir files = os.listdir(dir) - non_hidden_files_or_dirs = list(filter(does_not_start_with_do,files )) - print(non_hidden_files_or_dirs, 'filtered elements') - for content in files: - if one: - print(content) + + if hidden_files: + files.extend(['.', '..']) + + for file in files: + if hidden_files or not file.startswith('.'): + if one: + print(file) + else: + print(file, end=' ') if not one: - print(' '.join(files)) - + print() read_dir() \ No newline at end of file From 3969905959f2920119c23422782cdcfa3e85985c Mon Sep 17 00:00:00 2001 From: "[Elhadj Abdoul Diallo]" <[elhhabdouldiallo@gmail.com]> Date: Thu, 6 Mar 2025 12:52:33 +0000 Subject: [PATCH 17/40] Refactor ls command variable names for clarity and consistency --- implement-shell-tools/ls/ls.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/implement-shell-tools/ls/ls.py b/implement-shell-tools/ls/ls.py index 564adb7..f2ba6d3 100644 --- a/implement-shell-tools/ls/ls.py +++ b/implement-shell-tools/ls/ls.py @@ -17,21 +17,21 @@ def does_not_start_with_do(filename): return not filename.startswith('.') def read_dir(): - one = args.one - hidden_files = args.hidden_files + is_file_per_line_option = args.one + is_hidden_option = args.hidden_files dir = args.dir files = os.listdir(dir) - if hidden_files: + if is_hidden_option: files.extend(['.', '..']) for file in files: - if hidden_files or not file.startswith('.'): - if one: + if is_hidden_option or not file.startswith('.'): + if is_file_per_line_option : print(file) else: print(file, end=' ') - if not one: + if not is_file_per_line_option : print() read_dir() \ No newline at end of file From 6e2cad20444d8f4f6533ee0ab9a7392399de5f10 Mon Sep 17 00:00:00 2001 From: "[Elhadj Abdoul Diallo]" <[elhhabdouldiallo@gmail.com]> Date: Thu, 6 Mar 2025 12:55:18 +0000 Subject: [PATCH 18/40] Rename read_dir function to list_directory_contents for clarity and improve formatting in ls command --- implement-shell-tools/ls/ls.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/implement-shell-tools/ls/ls.py b/implement-shell-tools/ls/ls.py index f2ba6d3..586817e 100644 --- a/implement-shell-tools/ls/ls.py +++ b/implement-shell-tools/ls/ls.py @@ -13,10 +13,8 @@ args = parser.parse_args() -def does_not_start_with_do(filename): - return not filename.startswith('.') -def read_dir(): +def list_directory_contents(): is_file_per_line_option = args.one is_hidden_option = args.hidden_files dir = args.dir @@ -27,11 +25,11 @@ def read_dir(): for file in files: if is_hidden_option or not file.startswith('.'): - if is_file_per_line_option : + if is_file_per_line_option: print(file) else: print(file, end=' ') - if not is_file_per_line_option : + if not is_file_per_line_option: print() -read_dir() \ No newline at end of file +list_directory_contents() \ No newline at end of file From 80db8ec04c98b3f59bd271156006a00247601583 Mon Sep 17 00:00:00 2001 From: "[Elhadj Abdoul Diallo]" <[elhhabdouldiallo@gmail.com]> Date: Thu, 6 Mar 2025 13:29:46 +0000 Subject: [PATCH 19/40] Fix hidden files handling in ls command to prepend '.' and '..' when listing --- implement-shell-tools/ls/ls.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/implement-shell-tools/ls/ls.py b/implement-shell-tools/ls/ls.py index 586817e..e13eba9 100644 --- a/implement-shell-tools/ls/ls.py +++ b/implement-shell-tools/ls/ls.py @@ -21,7 +21,7 @@ def list_directory_contents(): files = os.listdir(dir) if is_hidden_option: - files.extend(['.', '..']) + files = ['.', '..'] + files for file in files: if is_hidden_option or not file.startswith('.'): From 4b7afa0a9cc2e266aec60916163118592c174541 Mon Sep 17 00:00:00 2001 From: "[Elhadj Abdoul Diallo]" <[elhhabdouldiallo@gmail.com]> Date: Thu, 6 Mar 2025 13:51:29 +0000 Subject: [PATCH 20/40] Add wc command implementation to read and display file content --- implement-shell-tools/wc/wc.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 implement-shell-tools/wc/wc.py diff --git a/implement-shell-tools/wc/wc.py b/implement-shell-tools/wc/wc.py new file mode 100644 index 0000000..4dff720 --- /dev/null +++ b/implement-shell-tools/wc/wc.py @@ -0,0 +1,27 @@ + +import argparse + + +parser = argparse.ArgumentParser( + prog="wc program", + description="Implements the cat program" +) + +parser.add_argument("path", type=str, help="The path to process") + +args = parser.parse_args() + + +def extract_lines(content): + return content.split('\n') + + +def read_file_content(file_path): + with open(file_path, 'r') as file: + content = file.read() + print(content) + lines = extract_lines(content) + return lines + +lines = read_file_content(args.path) +print(lines) \ No newline at end of file From 65c26539cdd17adb18e0840330739994f7761144 Mon Sep 17 00:00:00 2001 From: "[Elhadj Abdoul Diallo]" <[elhhabdouldiallo@gmail.com]> Date: Thu, 6 Mar 2025 13:54:11 +0000 Subject: [PATCH 21/40] Enhance wc command: trim empty lines from content and add line counting function --- implement-shell-tools/wc/wc.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/implement-shell-tools/wc/wc.py b/implement-shell-tools/wc/wc.py index 4dff720..3b3604d 100644 --- a/implement-shell-tools/wc/wc.py +++ b/implement-shell-tools/wc/wc.py @@ -13,7 +13,10 @@ def extract_lines(content): - return content.split('\n') + lines = content.split('\n') + if lines and lines[-1] == '': + lines = lines[:-1] + return lines def read_file_content(file_path): @@ -23,5 +26,7 @@ def read_file_content(file_path): lines = extract_lines(content) return lines +def number_of_lines(lines): + return len(lines) + lines = read_file_content(args.path) -print(lines) \ No newline at end of file From f9f4f1bf541b9ec886c70a3217c00006348a4f97 Mon Sep 17 00:00:00 2001 From: "[Elhadj Abdoul Diallo]" <[elhhabdouldiallo@gmail.com]> Date: Thu, 6 Mar 2025 13:56:41 +0000 Subject: [PATCH 22/40] Add function to output line count and file path in wc command --- implement-shell-tools/wc/wc.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/implement-shell-tools/wc/wc.py b/implement-shell-tools/wc/wc.py index 3b3604d..9c10a58 100644 --- a/implement-shell-tools/wc/wc.py +++ b/implement-shell-tools/wc/wc.py @@ -29,4 +29,9 @@ def read_file_content(file_path): def number_of_lines(lines): return len(lines) -lines = read_file_content(args.path) + +def output_lines_words_chars_number(): + lines = read_file_content(args.path) + print(len(lines), args.path) + +output_lines_words_chars_number() \ No newline at end of file From c31cb360e8146d4bd8c0c60b068eab925a8882f6 Mon Sep 17 00:00:00 2001 From: "[Elhadj Abdoul Diallo]" <[elhhabdouldiallo@gmail.com]> Date: Thu, 6 Mar 2025 13:58:52 +0000 Subject: [PATCH 23/40] Refactor read_file_content to return content directly and streamline line extraction in output function --- implement-shell-tools/wc/wc.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/implement-shell-tools/wc/wc.py b/implement-shell-tools/wc/wc.py index 9c10a58..61484eb 100644 --- a/implement-shell-tools/wc/wc.py +++ b/implement-shell-tools/wc/wc.py @@ -21,17 +21,15 @@ def extract_lines(content): def read_file_content(file_path): with open(file_path, 'r') as file: - content = file.read() - print(content) - lines = extract_lines(content) - return lines + return file.read() def number_of_lines(lines): return len(lines) def output_lines_words_chars_number(): - lines = read_file_content(args.path) + content = read_file_content(args.path) + lines = extract_lines(content) print(len(lines), args.path) output_lines_words_chars_number() \ No newline at end of file From 3dd6a355b15d5ff180d88abd4ddfd024e09af02d Mon Sep 17 00:00:00 2001 From: "[Elhadj Abdoul Diallo]" <[elhhabdouldiallo@gmail.com]> Date: Thu, 6 Mar 2025 14:01:21 +0000 Subject: [PATCH 24/40] Add function to extract words and update output to include word count in wc command --- implement-shell-tools/wc/wc.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/implement-shell-tools/wc/wc.py b/implement-shell-tools/wc/wc.py index 61484eb..12bfd5f 100644 --- a/implement-shell-tools/wc/wc.py +++ b/implement-shell-tools/wc/wc.py @@ -18,6 +18,8 @@ def extract_lines(content): lines = lines[:-1] return lines +def extract_words(content): + return content.split(' ') def read_file_content(file_path): with open(file_path, 'r') as file: @@ -30,6 +32,7 @@ def number_of_lines(lines): def output_lines_words_chars_number(): content = read_file_content(args.path) lines = extract_lines(content) - print(len(lines), args.path) + words = extract_words(content) + print(len(lines), len(words), args.path) output_lines_words_chars_number() \ No newline at end of file From 3fda7b2d2186be52b812c21d56cb49c04deb376b Mon Sep 17 00:00:00 2001 From: "[Elhadj Abdoul Diallo]" <[elhhabdouldiallo@gmail.com]> Date: Thu, 6 Mar 2025 14:03:13 +0000 Subject: [PATCH 25/40] Add function to extract characters and update output to include character count in wc command --- implement-shell-tools/wc/wc.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/implement-shell-tools/wc/wc.py b/implement-shell-tools/wc/wc.py index 12bfd5f..e8b4928 100644 --- a/implement-shell-tools/wc/wc.py +++ b/implement-shell-tools/wc/wc.py @@ -21,6 +21,9 @@ def extract_lines(content): def extract_words(content): return content.split(' ') +def extract_chars(content): + return list(content) + def read_file_content(file_path): with open(file_path, 'r') as file: return file.read() @@ -33,6 +36,7 @@ def output_lines_words_chars_number(): content = read_file_content(args.path) lines = extract_lines(content) words = extract_words(content) - print(len(lines), len(words), args.path) + chars = extract_chars(content) + print(len(lines), len(words), len(chars), args.path) output_lines_words_chars_number() \ No newline at end of file From 78aff8108ef815348b53b629a333345c3c99405a Mon Sep 17 00:00:00 2001 From: "[Elhadj Abdoul Diallo]" <[elhhabdouldiallo@gmail.com]> Date: Thu, 6 Mar 2025 14:03:41 +0000 Subject: [PATCH 26/40] Remove unused number_of_lines function to streamline wc command implementation --- implement-shell-tools/wc/wc.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/implement-shell-tools/wc/wc.py b/implement-shell-tools/wc/wc.py index e8b4928..e529c69 100644 --- a/implement-shell-tools/wc/wc.py +++ b/implement-shell-tools/wc/wc.py @@ -28,9 +28,6 @@ def read_file_content(file_path): with open(file_path, 'r') as file: return file.read() -def number_of_lines(lines): - return len(lines) - def output_lines_words_chars_number(): content = read_file_content(args.path) From e6d6afeaa9c9f9b02ca29284ee66e9b2fe402243 Mon Sep 17 00:00:00 2001 From: "[Elhadj Abdoul Diallo]" <[elhhabdouldiallo@gmail.com]> Date: Thu, 6 Mar 2025 14:07:12 +0000 Subject: [PATCH 27/40] Update wc command to accept multiple file paths and adjust output function accordingly --- implement-shell-tools/wc/wc.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/implement-shell-tools/wc/wc.py b/implement-shell-tools/wc/wc.py index e529c69..278f501 100644 --- a/implement-shell-tools/wc/wc.py +++ b/implement-shell-tools/wc/wc.py @@ -7,7 +7,7 @@ description="Implements the cat program" ) -parser.add_argument("path", type=str, help="The path to process") +parser.add_argument("paths", nargs='+', type=str, help="The path to process") args = parser.parse_args() @@ -29,11 +29,12 @@ def read_file_content(file_path): return file.read() -def output_lines_words_chars_number(): - content = read_file_content(args.path) +def output_lines_words_chars_number(file_path): + content = read_file_content(file_path) lines = extract_lines(content) words = extract_words(content) chars = extract_chars(content) - print(len(lines), len(words), len(chars), args.path) + print(len(lines), len(words), len(chars), file_path) -output_lines_words_chars_number() \ No newline at end of file +for file_path in args.paths: + output_lines_words_chars_number(file_path) \ No newline at end of file From 1be9fbef6280108ab68eadb8c78dd195017c0075 Mon Sep 17 00:00:00 2001 From: "[Elhadj Abdoul Diallo]" <[elhhabdouldiallo@gmail.com]> Date: Thu, 6 Mar 2025 14:40:51 +0000 Subject: [PATCH 28/40] Refactor wc command to return counts as a list and handle multiple file paths in output --- implement-shell-tools/wc/wc.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/implement-shell-tools/wc/wc.py b/implement-shell-tools/wc/wc.py index 278f501..bb06802 100644 --- a/implement-shell-tools/wc/wc.py +++ b/implement-shell-tools/wc/wc.py @@ -29,12 +29,20 @@ def read_file_content(file_path): return file.read() -def output_lines_words_chars_number(file_path): +def get_lines_words_chars_count(file_path): content = read_file_content(file_path) lines = extract_lines(content) words = extract_words(content) chars = extract_chars(content) - print(len(lines), len(words), len(chars), file_path) - -for file_path in args.paths: - output_lines_words_chars_number(file_path) \ No newline at end of file + return [len(lines), len(words), len(chars)] + +lines_words_chars_count = [] +if len(args.paths) == 1: + result = get_lines_words_chars_count(args.paths[0]) + print(result[0], result[1], result[2], args.paths[0]) +else: + for file_path in args.paths: + result = get_lines_words_chars_count(file_path) + lines_words_chars_count.append(result) + +print(lines_words_chars_count) \ No newline at end of file From 5d7f354dfe51212650ff998a3cdc0070a6ae6d1d Mon Sep 17 00:00:00 2001 From: "[Elhadj Abdoul Diallo]" <[elhhabdouldiallo@gmail.com]> Date: Thu, 6 Mar 2025 14:47:47 +0000 Subject: [PATCH 29/40] Refactor output handling in wc command to improve readability and streamline output for single file paths --- implement-shell-tools/wc/wc.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/implement-shell-tools/wc/wc.py b/implement-shell-tools/wc/wc.py index bb06802..8b83852 100644 --- a/implement-shell-tools/wc/wc.py +++ b/implement-shell-tools/wc/wc.py @@ -36,13 +36,20 @@ def get_lines_words_chars_count(file_path): chars = extract_chars(content) return [len(lines), len(words), len(chars)] + +def output_lines_words_chars_count(file_path): + lines_words_chars_count = get_lines_words_chars_count(file_path) + lines_count = lines_words_chars_count[0] + words_count = lines_words_chars_count[1] + chars_count = lines_words_chars_count[2] + print(lines_count, words_count, chars_count, args.paths[0]) + lines_words_chars_count = [] if len(args.paths) == 1: - result = get_lines_words_chars_count(args.paths[0]) - print(result[0], result[1], result[2], args.paths[0]) + output_lines_words_chars_count(args.paths[0]) else: for file_path in args.paths: result = get_lines_words_chars_count(file_path) lines_words_chars_count.append(result) -print(lines_words_chars_count) \ No newline at end of file +#print(lines_words_chars_count) \ No newline at end of file From 716ab4045725c93fb97715432aae6a93c3277859 Mon Sep 17 00:00:00 2001 From: "[Elhadj Abdoul Diallo]" <[elhhabdouldiallo@gmail.com]> Date: Thu, 6 Mar 2025 15:06:33 +0000 Subject: [PATCH 30/40] Enhance wc command output to display individual file counts and total counts for multiple files --- implement-shell-tools/wc/wc.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/implement-shell-tools/wc/wc.py b/implement-shell-tools/wc/wc.py index 8b83852..c420ac3 100644 --- a/implement-shell-tools/wc/wc.py +++ b/implement-shell-tools/wc/wc.py @@ -42,7 +42,13 @@ def output_lines_words_chars_count(file_path): lines_count = lines_words_chars_count[0] words_count = lines_words_chars_count[1] chars_count = lines_words_chars_count[2] - print(lines_count, words_count, chars_count, args.paths[0]) + print(lines_count, words_count, chars_count, file_path) + +def output_total_lines(lines_words_chars_count, total): + total_lines = sum(count[0] for count in lines_words_chars_count) + total_words = sum(count[1] for count in lines_words_chars_count) + total_chars = sum(count[2] for count in lines_words_chars_count) + print(total_lines, total_words, total_chars, total) lines_words_chars_count = [] if len(args.paths) == 1: @@ -51,5 +57,5 @@ def output_lines_words_chars_count(file_path): for file_path in args.paths: result = get_lines_words_chars_count(file_path) lines_words_chars_count.append(result) - -#print(lines_words_chars_count) \ No newline at end of file + output_lines_words_chars_count(file_path) + output_total_lines(lines_words_chars_count, 'total') \ No newline at end of file From af6a6a7332ec78b5a5715fd40e0daa2cdb118b51 Mon Sep 17 00:00:00 2001 From: "[Elhadj Abdoul Diallo]" <[elhhabdouldiallo@gmail.com]> Date: Thu, 6 Mar 2025 15:34:00 +0000 Subject: [PATCH 31/40] Add option to output only line counts in wc command --- implement-shell-tools/wc/wc.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/implement-shell-tools/wc/wc.py b/implement-shell-tools/wc/wc.py index c420ac3..9eed4c8 100644 --- a/implement-shell-tools/wc/wc.py +++ b/implement-shell-tools/wc/wc.py @@ -8,6 +8,7 @@ ) parser.add_argument("paths", nargs='+', type=str, help="The path to process") +parser.add_argument('-l', '--lines', action="store_true", help='Ouput number of lines') args = parser.parse_args() @@ -39,10 +40,16 @@ def get_lines_words_chars_count(file_path): def output_lines_words_chars_count(file_path): lines_words_chars_count = get_lines_words_chars_count(file_path) + is_lines_option = args.lines + lines_count = lines_words_chars_count[0] words_count = lines_words_chars_count[1] chars_count = lines_words_chars_count[2] - print(lines_count, words_count, chars_count, file_path) + + if is_lines_option: + print(lines_count, file_path) + else: + print(lines_count, words_count, chars_count, file_path) def output_total_lines(lines_words_chars_count, total): total_lines = sum(count[0] for count in lines_words_chars_count) From 282e9ccc28bf54fd15de264f775469fa96f166b0 Mon Sep 17 00:00:00 2001 From: "[Elhadj Abdoul Diallo]" <[elhhabdouldiallo@gmail.com]> Date: Thu, 6 Mar 2025 15:35:46 +0000 Subject: [PATCH 32/40] Add option to output word counts in wc command --- implement-shell-tools/wc/wc.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/implement-shell-tools/wc/wc.py b/implement-shell-tools/wc/wc.py index 9eed4c8..d2d9298 100644 --- a/implement-shell-tools/wc/wc.py +++ b/implement-shell-tools/wc/wc.py @@ -9,6 +9,7 @@ parser.add_argument("paths", nargs='+', type=str, help="The path to process") parser.add_argument('-l', '--lines', action="store_true", help='Ouput number of lines') +parser.add_argument('-w', '--words', action="store_true", help='Ouput number of words') args = parser.parse_args() @@ -41,6 +42,7 @@ def get_lines_words_chars_count(file_path): def output_lines_words_chars_count(file_path): lines_words_chars_count = get_lines_words_chars_count(file_path) is_lines_option = args.lines + is_words_option = args.words lines_count = lines_words_chars_count[0] words_count = lines_words_chars_count[1] @@ -48,6 +50,8 @@ def output_lines_words_chars_count(file_path): if is_lines_option: print(lines_count, file_path) + elif is_words_option: + print(words_count, file_path) else: print(lines_count, words_count, chars_count, file_path) From 6fcf115d824258954d58aef569dfe9087c7d9b6d Mon Sep 17 00:00:00 2001 From: "[Elhadj Abdoul Diallo]" <[elhhabdouldiallo@gmail.com]> Date: Thu, 6 Mar 2025 15:37:22 +0000 Subject: [PATCH 33/40] Add option to output character counts in wc command --- implement-shell-tools/wc/wc.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/implement-shell-tools/wc/wc.py b/implement-shell-tools/wc/wc.py index d2d9298..4df3c70 100644 --- a/implement-shell-tools/wc/wc.py +++ b/implement-shell-tools/wc/wc.py @@ -10,6 +10,7 @@ parser.add_argument("paths", nargs='+', type=str, help="The path to process") parser.add_argument('-l', '--lines', action="store_true", help='Ouput number of lines') parser.add_argument('-w', '--words', action="store_true", help='Ouput number of words') +parser.add_argument('-c', '--chars', action="store_true", help='Ouput number of characters') args = parser.parse_args() @@ -43,6 +44,7 @@ def output_lines_words_chars_count(file_path): lines_words_chars_count = get_lines_words_chars_count(file_path) is_lines_option = args.lines is_words_option = args.words + is_chars_option = args.chars lines_count = lines_words_chars_count[0] words_count = lines_words_chars_count[1] @@ -52,6 +54,8 @@ def output_lines_words_chars_count(file_path): print(lines_count, file_path) elif is_words_option: print(words_count, file_path) + elif is_chars_option: + print(chars_count, file_path) else: print(lines_count, words_count, chars_count, file_path) From 39b5783e1c1663b4358526ab887f753952fc087c Mon Sep 17 00:00:00 2001 From: "[Elhadj Abdoul Diallo]" <[elhhabdouldiallo@gmail.com]> Date: Thu, 6 Mar 2025 15:44:47 +0000 Subject: [PATCH 34/40] Refactor wc command to streamline option handling and improve output based on selected flags --- implement-shell-tools/wc/wc.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/implement-shell-tools/wc/wc.py b/implement-shell-tools/wc/wc.py index 4df3c70..3affb75 100644 --- a/implement-shell-tools/wc/wc.py +++ b/implement-shell-tools/wc/wc.py @@ -13,6 +13,9 @@ parser.add_argument('-c', '--chars', action="store_true", help='Ouput number of characters') args = parser.parse_args() +is_lines_option = args.lines +is_words_option = args.words +is_chars_option = args.chars def extract_lines(content): @@ -42,10 +45,7 @@ def get_lines_words_chars_count(file_path): def output_lines_words_chars_count(file_path): lines_words_chars_count = get_lines_words_chars_count(file_path) - is_lines_option = args.lines - is_words_option = args.words - is_chars_option = args.chars - + lines_count = lines_words_chars_count[0] words_count = lines_words_chars_count[1] chars_count = lines_words_chars_count[2] @@ -63,7 +63,15 @@ def output_total_lines(lines_words_chars_count, total): total_lines = sum(count[0] for count in lines_words_chars_count) total_words = sum(count[1] for count in lines_words_chars_count) total_chars = sum(count[2] for count in lines_words_chars_count) - print(total_lines, total_words, total_chars, total) + + if is_lines_option: + print(total_lines, total) + elif is_words_option: + print(total_words, total) + elif is_chars_option: + print(total_chars, total) + else: + print(total_lines, total_words, total_chars, total) lines_words_chars_count = [] if len(args.paths) == 1: From d889bf4ebcc34f43964b173230728d994bf961cd Mon Sep 17 00:00:00 2001 From: "[Elhadj Abdoul Diallo]" <[elhhabdouldiallo@gmail.com]> Date: Thu, 6 Mar 2025 15:49:13 +0000 Subject: [PATCH 35/40] Rename output functions in wc command for clarity and consistency --- implement-shell-tools/wc/wc.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/implement-shell-tools/wc/wc.py b/implement-shell-tools/wc/wc.py index 3affb75..ed250e9 100644 --- a/implement-shell-tools/wc/wc.py +++ b/implement-shell-tools/wc/wc.py @@ -43,7 +43,7 @@ def get_lines_words_chars_count(file_path): return [len(lines), len(words), len(chars)] -def output_lines_words_chars_count(file_path): +def print_selected_counts(file_path): lines_words_chars_count = get_lines_words_chars_count(file_path) lines_count = lines_words_chars_count[0] @@ -59,7 +59,7 @@ def output_lines_words_chars_count(file_path): else: print(lines_count, words_count, chars_count, file_path) -def output_total_lines(lines_words_chars_count, total): +def print_total_lines(lines_words_chars_count, total): total_lines = sum(count[0] for count in lines_words_chars_count) total_words = sum(count[1] for count in lines_words_chars_count) total_chars = sum(count[2] for count in lines_words_chars_count) @@ -75,10 +75,10 @@ def output_total_lines(lines_words_chars_count, total): lines_words_chars_count = [] if len(args.paths) == 1: - output_lines_words_chars_count(args.paths[0]) + print_selected_counts(args.paths[0]) else: for file_path in args.paths: result = get_lines_words_chars_count(file_path) lines_words_chars_count.append(result) - output_lines_words_chars_count(file_path) - output_total_lines(lines_words_chars_count, 'total') \ No newline at end of file + print_selected_counts(file_path) + print_total_lines(lines_words_chars_count, 'total') \ No newline at end of file From f2c55db946c18cf2094229d0cc6b8f890f138982 Mon Sep 17 00:00:00 2001 From: "[Elhadj Abdoul Diallo]" <[elhhabdouldiallo@gmail.com]> Date: Thu, 6 Mar 2025 15:55:27 +0000 Subject: [PATCH 36/40] Encapsulate file statistics printing logic in a dedicated function --- implement-shell-tools/wc/wc.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/implement-shell-tools/wc/wc.py b/implement-shell-tools/wc/wc.py index ed250e9..72d9aeb 100644 --- a/implement-shell-tools/wc/wc.py +++ b/implement-shell-tools/wc/wc.py @@ -73,12 +73,15 @@ def print_total_lines(lines_words_chars_count, total): else: print(total_lines, total_words, total_chars, total) -lines_words_chars_count = [] -if len(args.paths) == 1: - print_selected_counts(args.paths[0]) -else: - for file_path in args.paths: - result = get_lines_words_chars_count(file_path) - lines_words_chars_count.append(result) - print_selected_counts(file_path) - print_total_lines(lines_words_chars_count, 'total') \ No newline at end of file +def print_file_statistics(): + lines_words_chars_count = [] + if len(args.paths) == 1: + print_selected_counts(args.paths[0]) + else: + for file_path in args.paths: + result = get_lines_words_chars_count(file_path) + lines_words_chars_count.append(result) + print_selected_counts(file_path) + print_total_lines(lines_words_chars_count, 'total') + +print_file_statistics() From d6c6577b64fe76f3cf76b7f3a66c1d60224dcb7d Mon Sep 17 00:00:00 2001 From: "[Elhadj Abdoul Diallo]" <[elhhabdouldiallo@gmail.com]> Date: Thu, 6 Mar 2025 15:59:36 +0000 Subject: [PATCH 37/40] Simplify print statements in wc command for improved readability --- implement-shell-tools/wc/wc.py | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/implement-shell-tools/wc/wc.py b/implement-shell-tools/wc/wc.py index 72d9aeb..a812c56 100644 --- a/implement-shell-tools/wc/wc.py +++ b/implement-shell-tools/wc/wc.py @@ -50,28 +50,20 @@ def print_selected_counts(file_path): words_count = lines_words_chars_count[1] chars_count = lines_words_chars_count[2] - if is_lines_option: - print(lines_count, file_path) - elif is_words_option: - print(words_count, file_path) - elif is_chars_option: - print(chars_count, file_path) - else: - print(lines_count, words_count, chars_count, file_path) + if is_lines_option: print(lines_count, file_path) + elif is_words_option: print(words_count, file_path) + elif is_chars_option: print(chars_count, file_path) + else: print(lines_count, words_count, chars_count, file_path) def print_total_lines(lines_words_chars_count, total): total_lines = sum(count[0] for count in lines_words_chars_count) total_words = sum(count[1] for count in lines_words_chars_count) total_chars = sum(count[2] for count in lines_words_chars_count) - if is_lines_option: - print(total_lines, total) - elif is_words_option: - print(total_words, total) - elif is_chars_option: - print(total_chars, total) - else: - print(total_lines, total_words, total_chars, total) + if is_lines_option: print(total_lines, total) + elif is_words_option: print(total_words, total) + elif is_chars_option: print(total_chars, total) + else: print(total_lines, total_words, total_chars, total) def print_file_statistics(): lines_words_chars_count = [] From b8d801b5775d4142abfd09e4e72524e57982e5e6 Mon Sep 17 00:00:00 2001 From: "[Elhadj Abdoul Diallo]" <[elhhabdouldiallo@gmail.com]> Date: Sat, 15 Mar 2025 08:31:55 +0000 Subject: [PATCH 38/40] Add .venv directory to .gitignore to prevent tracking of virtual environment files --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 3c3629e..dd4c3ba 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ node_modules +implement-cowsay/.venv. \ No newline at end of file From b3848845bbe21bc9d25a6d6d2d1dca5fc9878bb8 Mon Sep 17 00:00:00 2001 From: "[Elhadj Abdoul Diallo]" <[elhhabdouldiallo@gmail.com]> Date: Sat, 15 Mar 2025 10:14:45 +0000 Subject: [PATCH 39/40] Remove commented debug print statement in cat command --- implement-shell-tools/cat/cat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/implement-shell-tools/cat/cat.py b/implement-shell-tools/cat/cat.py index 1881221..9f34e44 100644 --- a/implement-shell-tools/cat/cat.py +++ b/implement-shell-tools/cat/cat.py @@ -10,7 +10,7 @@ parser.add_argument("paths", nargs='+', help="The files to search") args = parser.parse_args() - +#print(args.paths, '<====paths list') def read_file_content(file_path): with open(file_path, 'r') as f: return f.read() From cafe718f9c6a90967d2bff82b5d0c61df72cd5bc Mon Sep 17 00:00:00 2001 From: "[Elhadj Abdoul Diallo]" <[elhhabdouldiallo@gmail.com]> Date: Sun, 16 Mar 2025 15:17:58 +0000 Subject: [PATCH 40/40] Remove commented debug print statement in cat command --- implement-shell-tools/cat/cat.py | 1 - 1 file changed, 1 deletion(-) diff --git a/implement-shell-tools/cat/cat.py b/implement-shell-tools/cat/cat.py index 9f34e44..a332520 100644 --- a/implement-shell-tools/cat/cat.py +++ b/implement-shell-tools/cat/cat.py @@ -10,7 +10,6 @@ parser.add_argument("paths", nargs='+', help="The files to search") args = parser.parse_args() -#print(args.paths, '<====paths list') def read_file_content(file_path): with open(file_path, 'r') as f: return f.read()