Skip to content

Instantly share code, notes, and snippets.

@ttdoda
Created November 19, 2023 16:12
Show Gist options
  • Save ttdoda/0420f1f88d633e925c86a9a900605d24 to your computer and use it in GitHub Desktop.
Save ttdoda/0420f1f88d633e925c86a9a900605d24 to your computer and use it in GitHub Desktop.
xterm付属のresizeコマンドのbashスクリプトによる手抜き再実装
#!/bin/bash
#
# resize.bash -- resize コマンドの手抜き再実装 (bashスクリプト)
#
# xterm の付属コマンド resize[*1] の機能の内、端末(エミュレータ)の現在の
# サイズを調べて TTY の設定を合わせる機能の実装例です。
#
# 原理:
# rubyスクリプト版[*2]を参照
#
# *1: http://invisible-island.net/xterm/manpage/resize.html
# *2: https://gist.github.com/ttdoda/413834b50497d63feadad750ce787c85
#
# License: CC0
echo -ne "\e7\e[9999;9999H\e[6n\e8" >&0
IFS="[" read -d R -n 14 -t 1 -s dummy pos
eval $(echo $pos | { IFS=";" read rows cols; echo "rows=$rows; cols=$cols"; })
if [ -n "$rows" -a -n "$cols" ]; then
stty cols $cols rows $rows
echo "COLUMNS=$cols;"
echo "LINES=$rows;"
echo "export COLUMNS LINES;"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment