Last active
December 14, 2024 16:33
-
-
Save ninlith/115fddc6e3945a96ecfdcb23612954c8 to your computer and use it in GitHub Desktop.
Fitcat. A cat that truncates long lines.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Fitcat. A cat that truncates long lines. | |
import contextlib, os, shutil, sys | |
try: | |
width = os.get_terminal_size(sys.stdin.fileno()).columns | |
except OSError: | |
width = shutil.get_terminal_size().columns | |
with contextlib.ExitStack() as stack, contextlib.suppress(BrokenPipeError): | |
for f in [stack.enter_context(open(fname)) for fname in sys.argv[1:]]: | |
[print(line[:width].rstrip()) for line in f] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment