Guest User

Smartpage

a guest
Nov 16th, 2014
433
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/sh
  2. #
  3. # Smartpage: use the pager only if the output does not fit on the screen
  4. #
  5. # This program is using the GNU/GPLv3 License <http://www.gnu.org/licenses/>
  6.  
  7. REAL_PAGER="less -r"
  8. FILE="/tmp/.pager"
  9. WIDTH="$(stty size | cut -d ' ' -f 2)"
  10. HEIGHT="$(stty size | cut -d ' ' -f 1)"
  11.  
  12. fold -w "$WIDTH" "$@" > "$FILE"
  13. chmod 600 "$FILE"
  14. if [ "$(wc -l "$FILE" | cut -d ' ' -f 1)" -lt "$HEIGHT" ] ; then
  15.     cat "$FILE"
  16. else
  17.     $REAL_PAGER "$FILE"
  18. fi
  19. rm "$FILE"
RAW Paste Data