home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 21.9 Keep File Printouts Up-to-Date Automatically with make Chapter 21
More About Managing Files
Next: 21.11 Safer Removing, Moving, and Copying
 

21.10 Keep a Directory Listing at Top of the Screen: dirtop

When I'm cleaning out a directory, I'm always using ls to see what files are there. When I have a terminal with windows, I can keep an ls listing in one window and do cleanup in another. In a terminal without windows, I use this script named dirtop . It clears the screen, puts an ls listing at the top of the screen, and sends an escape sequence (5.8 ) to the terminal that makes the screen top nonscrolling. So, as I type my commands, they scroll "underneath" the ls listing at the top without disturbing it. If I use a command like vi that resets the screen, I just use dirtop again when the command is done. When I'm done, the command dirtop -c clears the screen and makes the whole screen scrollable again.

This script works only on VT100-type terminals and compatibles because the escape sequences are hardcoded into it. It should probably be rewritten to use termcap or terminfo information so it'd work on more terminals. Luckily, there are lots of VT100-compatible terminals and communications programs.





THE...
 


echo...33'
 












`..`
 













#! /bin/sh

ls="/bin/ls -CF"                # ls command to use
maxlines=10     # if more lines in listing than this, quit
# UNCOMMENT THE LINE FOR YOUR SYSTEM:
cmd=echo   c='\c'   e='\033'   n=                       # SysV
#cmd=/usr/5bin/echo   c='\c'   e='\033'   n=            # SunOS
#cmd=/bin/echo   c=   e="`echo e | tr e '\033'`"   n=-n # BSD

case "$1" in
-c) $cmd $n "${e}[r${e}[2J${c}"; exit 0;; # just reset screen
"") ;;
*) echo "Usage: `basename $0` [-c]" 1>&2; exit 1 ;;
esac

temp=/tmp/DIRTOP$$
trap 'rm -f $temp; exit' 0 1 2 15

$ls > $temp
# set number of lines to clear: one more than length of ls listing:
lines=`expr 1 + \`wc -l < $temp\``
if [ $lines -gt $maxlines ]
then
    echo "`basename $0`: Directory listing > $maxlines lines" 1>&2
    exit 1
else
    # CLEAR SCREEN.  SET NO-SCROLL AREA:
    $cmd $n "${e}[2J${c}"
    $cmd $n "${e}[${lines};24r${c}"
    # MOVE CURSOR TO TOP-LEFT CORNER, THEN PRINT LISTING:
    $cmd $n "${e}[0;0f${c}"
    cat $temp
    exit
fi

- JP


Previous: 21.9 Keep File Printouts Up-to-Date Automatically with make UNIX Power Tools Next: 21.11 Safer Removing, Moving, and Copying
21.9 Keep File Printouts Up-to-Date Automatically with make Book Index 21.11 Safer Removing, Moving, and Copying

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System