From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1S0fWM-0007PL-QS for garchives@archives.gentoo.org; Thu, 23 Feb 2012 20:44:10 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id BD015E0F1C; Thu, 23 Feb 2012 20:43:51 +0000 (UTC) Received: from mail.muc.de (colin.muc.de [193.149.48.1]) by pigeon.gentoo.org (Postfix) with ESMTP id 0C0DEE0F09 for ; Thu, 23 Feb 2012 20:42:35 +0000 (UTC) Received: (qmail 37201 invoked by uid 3782); 23 Feb 2012 20:42:34 -0000 Received: from acm.muc.de (pD9557DC3.dip.t-dialin.net [217.85.125.195]) by colin.muc.de (tmda-ofmipd) with ESMTP; Thu, 23 Feb 2012 21:42:32 +0100 Received: (qmail 3875 invoked by uid 1000); 23 Feb 2012 20:42:00 -0000 Date: Thu, 23 Feb 2012 20:42:00 +0000 To: gentoo-user@lists.gentoo.org Subject: [gentoo-user] dog - man's best friend. Message-ID: <20120223204200.GE2834@acm.acm> Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-user@lists.gentoo.org Reply-to: gentoo-user@lists.gentoo.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-Delivery-Agent: TMDA/1.1.12 (Macallan) From: Alan Mackenzie X-Primary-Address: acm@muc.de X-Archives-Salt: 345fdc19-576b-43a1-8ac6-7de1c0f48d82 X-Archives-Hash: 1b558ce48957ecb72529fff45a34ec60 Hi, Gentoo! I've finally been pushed over the edge. I simply can't stand it any longer. The "it" in this case is viewing a file or process output and either: (a) using less, and have it take just 10 screen lines; (b) using cat etc., and have the interesting part scroll away. To solve this dilemma, I've written dog, a short script that will splat lines to the screen if they're few enough, invoke less otherwise. I've set the threshold between the two cases at 60 lines. If your screen is a different size, change the two obvious bits. Enjoy! dog: ######################################################################### #!/bin/bash export IFS="" lin=0 while [ $lin -lt 60 ] && read ; do buf[$lin]=$REPLY lin=$((lin + 1)) done if [ $lin -ge 60 ] ; then ( for (( i = 0 ; i < 60 ; i++ )) ; do echo ${buf[$i]} done while read ; do echo $REPLY done ) | less else for (( i = 0 ; i < $lin ; i++ )) ; do echo ${buf[$i]} done fi ######################################################################### -- Alan Mackenzie (Nuremberg, Germany).