From e3a51e12995dd4a9ca6306e91e46aac8e37baeb3 Mon Sep 17 00:00:00 2001 From: sij Date: Tue, 8 Oct 2024 06:40:59 +0200 Subject: [PATCH] Add nocomment --- nocomment | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 nocomment diff --git a/nocomment b/nocomment new file mode 100644 index 0000000..2cb655e --- /dev/null +++ b/nocomment @@ -0,0 +1,27 @@ +#!/usr/bin/env python3 + +import sys +import os + +def print_significant_lines(file_path): + try: + with open(file_path, 'r') as file: + for line in file: + # Strip whitespace from the beginning and end of the line + stripped_line = line.strip() + + # Check if the line is not empty, not whitespace, and not a comment + if stripped_line and not stripped_line.startswith('#'): + print(line.rstrip()) # Print the line without trailing newline + except FileNotFoundError: + print(f"Error: File '{file_path}' not found.", file=sys.stderr) + except IOError: + print(f"Error: Unable to read file '{file_path}'.", file=sys.stderr) + +if __name__ == "__main__": + if len(sys.argv) != 2: + print("Usage: nocomment ", file=sys.stderr) + sys.exit(1) + + file_path = sys.argv[1] + print_significant_lines(file_path)