Created
September 8, 2018 02:29
-
-
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
This file contains 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
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