Skip to content

Instantly share code, notes, and snippets.

@HeatfanJohn
Last active May 19, 2021 23:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HeatfanJohn/b734804b80908d36cacd706e692a6546 to your computer and use it in GitHub Desktop.
Save HeatfanJohn/b734804b80908d36cacd706e692a6546 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# This bash script dynamically sets the current tty's rows and cols
# to the device's physical size
#
# Below is typical call from ~/.bashrc
#if [ "/dev/ttyGS0" = "/dev/ttyGS0" ]; then
# export TERM='xterm'
# source ~/resize
#fi
#
res() {
old=$(stty -g)
stty raw -echo min 0 time 5
printf '\0337\033[r\033[999;999H\033[6n\0338' > /dev/tty
IFS='[;R' read -r _ rows cols _ < /dev/tty
stty "$old"
# echo "cols:$cols"
# echo "rows:$rows"
stty cols "$cols" rows "$rows"
}
res2() {
old=$(stty -g)
stty raw -echo min 0 time 5
printf '\033[18t' > /dev/tty
IFS=';t' read -r _ rows cols _ < /dev/tty
stty "$old"
# echo "cols:$cols"
# echo "rows:$rows"
stty cols "$cols" rows "$rows"
}
res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment