Skip to content

Instantly share code, notes, and snippets.

@the-c0d3r
Created September 8, 2018 02:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save the-c0d3r/9df76f458f1bf109423a4f40e00b4df5 to your computer and use it in GitHub Desktop.
Save the-c0d3r/9df76f458f1bf109423a4f40e00b4df5 to your computer and use it in GitHub Desktop.
use 'less' or 'cat' based on number of lines and how big is the terminal
function cat() {
if [ -f $1 ]; then
terminal_height=$(tput lines)
file_lines=$(wc -l < $1 | awk '{print $1}')
if (( $file_lines > $terminal_height )); then
less $1
else
/bin/cat $1
fi
else
echo "File: '$1' not found"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment