#!/bin/sh ruler="\ ....+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8....+....9....+....0....+....1....+....2....+....3....+....4....+....5....+....6....+....7..." # In case we're on SunOS4. PATH=${PATH}:/usr/5bin export PATH case "$1" in "" ) ;; -o ) tput cuu1 ;; * ) echo "Use: `basename $0` [-o]"; echo "Prints a ruler. Use option -o to overwrite the command line." ;; esac # Figure out our screensize. This is messy because stty is different on # every OS -- sometimes in 4 different versions! # Old berkeley-style stty needs to access stdout, and writes to stderr. # Modern stty accesses stdin, and writes to stdout. Test for these. stty -a 1>/dev/null 2>&1 case $? in 0 ) # Modern style. stty=`stty -a &1 >/dev/tty | grep columns` ;; esac # OK, $stty now contains a line like one of the following: # ..., 24 rows, 89 columns # ...; 24 rows; 86 columns # ...; rows 35; columns 80;... # rows = 24; columns = 90 # rows = 24; columns = 80;... # rows = 24 columns = 80;... # case "$stty" in *[0-9]\ rows* ) # nn rows, mm columns rows_cols=`echo "$stty" | sed -e \ 's/^.* \([0-9][0-9]*\) rows.* *\([0-9][0-9]*\) columns.*/\1 \2/'` ;; *\ rows\ [0-9]* ) # rows nn; columns mm rows_cols=`echo "$stty" | sed -e 's/^.* rows \([0-9][0-9]*\)[^0-9]*columns *\([0-9][0-9]*\)[^0-9]*.*/\1 \2/'` ;; * ) # rows = mm, columns = nn rows_cols=`echo "$stty" | sed -e 's/^.*rows = \([0-9][0-9]*\)[^0-9].*columns =[^0-9]*\([0-9][0-9]*\)[^0-9]*.*/\1 \2/'` ;; esac set -- $rows_cols cols=$2 n=`expr $cols - 1` expr substr "$ruler" 1 $n