Skip to content

Instantly share code, notes, and snippets.

@mbreese
Created February 15, 2023 14:52
Show Gist options
  • Save mbreese/dbf90beb0b3aa29d12ed9f0723a4de76 to your computer and use it in GitHub Desktop.
Save mbreese/dbf90beb0b3aa29d12ed9f0723a4de76 to your computer and use it in GitHub Desktop.
Quick script to convert stdin to a line size that fits the screen. For example, `ps -e` will return only lines that fit on the current screen. If you want to grep that output, you get all of the data and it wraps the screen. If you pipe `ps -e | grep foo | fit`, then you get the trimmed output again.
#!/bin/bash
COLS="$(tput cols)"
while read LINE; do
echo $LINE | head -c $COLS
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment