title: Would it be possible to automatically page the output in zsh?
body: <p>Sometimes we run a command in the terminal, and the output is too large, and we forgot to put "| less" in the end. So I am wondering would it possible to page the output when it is too large in zsh?</p>
  
  <p>I tried to implement this feature by using python and less:</p>
  
  <pre><code>#!/usr/bin/env python3
  termHeight = 25
  import sys
  from subprocess import Popen, PIPE
  p = Popen(['unbuffer'] + sys.argv[1:], stdin=PIPE, stdout=PIPE)
  lines = []
  for count in range(termHeight):
      line = p.stdout.readline()
      if not line:
          break
      print(line.decode('utf8'), end='')
      lines += [line]
  if line:
      q = Popen(['less', '-Mr'], stdin=PIPE)
      q.stdin.writelines(lines)
      while True:
          line = p.stdout.readline()
          if not line:
              break
          q.stdin.write(line)
      q.communicate()
  </code></pre>
  
  <p>let's save this python script to p.py. So when we run "python p.py some commands" like "python p.py ls --help", if the output is more than 25 lines, this script will use less to display the output.</p>
  
  <p>The problem is I can not get input from user. Which means this solution does not work with interactive program at all.</p>