Skip to content

Instantly share code, notes, and snippets.

@karlbunch
Last active June 24, 2018 10:26
Show Gist options
  • Save karlbunch/d31d96a4a4ec120cf409a3b948db810b to your computer and use it in GitHub Desktop.
Save karlbunch/d31d96a4a4ec120cf409a3b948db810b to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# resize - cheap bash implementation of the X11 resize command to avoid installing all the X11 stuff for one command
#
# Author: Karl Bunch <[email protected]>
#
# Created: Sat Sep 2 08:30:14 EDT 2017
#
if [ "X$1" = "X-s" -a -n "$2" -a -n "$3" ]; then
echo -ne "\033[8;$2;$3t"
fi
resp=$(echo -ne '\033[s\033[r\033[999;999H\033[6n\033[u' > /dev/tty;read -t 2 -s -d R f;echo $f)
eval $(echo "$resp" | sed 's/^.*\[\([0-9]*\);\([0-9]*\).*/COLUMNS=\2;LINES=\1;export COLUMNS LINES/')
echo -e "COLUMNS=${COLUMNS};\nLINES=${LINES}\nexport COLUMNS LINES;"
stty cols $COLUMNS rows $LINES
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment