Skip to content

Instantly share code, notes, and snippets.

@lantw44
Last active August 14, 2021 09:43
Show Gist options
  • Save lantw44/6578d3bd2b98e6797eb4bc9f27e1a11e to your computer and use it in GitHub Desktop.
Save lantw44/6578d3bd2b98e6797eb4bc9f27e1a11e to your computer and use it in GitHub Desktop.
#!/this/script/can/only/be/run/in/bash
get_terminal_size ()
{
# ESC 7 = 儲存游標位置和屬性
# ESC [r = 啟用全螢幕捲動
# ESC [{row};{col}H = 移動游標
# ESC 6n = 回報目前游標位置
# ESC 8 = 還原游標位置和屬性
printf '\e7\e[r\e[999;999H\e[6n\e8' 1>&2
read -r -s -d R getsize
printf '%s' "$getsize" | sed 's#..\([0-9]*\);\([0-9]*\)#LINES=\1 COLUMNS=\2#'
}
set_terminal_size ()
{
eval "export $(get_terminal_size)"
stty cols "$COLUMNS" rows "$LINES"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment