Skip to content

Instantly share code, notes, and snippets.

@ninlith
Last active December 14, 2024 16:33
Show Gist options
  • Save ninlith/115fddc6e3945a96ecfdcb23612954c8 to your computer and use it in GitHub Desktop.
Save ninlith/115fddc6e3945a96ecfdcb23612954c8 to your computer and use it in GitHub Desktop.
Fitcat. A cat that truncates long lines.
# 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