From c6b49621e421d7f0fc6693758371104de02e3c8a Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Wed, 13 Aug 2014 11:05:50 -0700 Subject: Resize script. --- resize | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100755 resize diff --git a/resize b/resize new file mode 100755 index 0000000..86cf3db --- /dev/null +++ b/resize @@ -0,0 +1,66 @@ +#!/bin/sh + +# +# resize - script to detect actual terminal window size +# and set the appropriate tty kernel params +# similarly to the 20+ year old resize program from X11. +# +# Kaz Kylheku +# October 2006 +# + +if [ $# -ne 0 ] ; then + echo This is not the X11 resize program, but a shell script imitation. + echo It does not process any arguments. + exit 1 +fi + +# put tty in raw mode +saved_tty=$(stty -g) +stty raw isig -echo + +# Save cursor position +printf "\0337" > /dev/tty + +# Position the cursor to location 999,999 +printf "\033[999;999H" > /dev/tty + +# Query the actual cursor position +printf "\033[6n" > /dev/tty + +# read tty response +# We use dd to read character by character +# until encountering the R letter, +# The response syntax is ESC[;R +while true; do + char=$(dd bs=1 count=1 2> /dev/null) + if [ "$char" = "R" ] ; then + break; + fi + tty_response="$tty_response$char" +done + +# Restore cursor position +printf "\0338" > /dev/tty + +# restore tty +stty $saved_tty + +# Set up tty +set_tty_params() +{ + stty rows $2 columns $3 + cat < and will be +# extracted as tokens, and passed to the +# function as $1, $2 and $3. +IFS='[;R' +set_tty_params $tty_response -- cgit v1.2.3