开发者

Bash command to change size of bash window

开发者 https://www.devze.com 2023-02-15 21:42 出处:网络
Is there any command to change size of bash开发者_Go百科 window( for example to set size on 150x90) ?

Is there any command to change size of bash开发者_Go百科 window ( for example to set size on 150x90) ? I dont want to change .profile file.


Some (but not many) terminals accept the ANSI escape sequence

\033[8;h;wt

(where \033 is the ASCII control character ESC, and h and w are height and width in decimal).

For example, in XTerm (after allowing window ops through the Ctrl-RMB menu or the allowWindowOps X resource),

$ printf '\033[8;40;100t'

will resize the window to 100x40 characters.


$ resize -s 90 150

see the file manual for more options.

$ man resize


The resize command works to change the size of the window, but you may experience some strange things if you don't also tell the terminal to use the whole area. This is what I use, and it works well.

#!/bin/bash
resize -s 33 100
stty rows 33
stty cols 100


I usually only want to change the console width, so combining answers/comments from ephemient and Jimmy MG Lim, I came up with this little script:

#!/bin/bash
set -u

cols="$1"
rows="$(stty size | cut -d ' ' -f 1)"

printf '\033[8;%d;%dt' $rows $cols


This is probably a question for https://superuser.com/, anyways, how do you launch your terminal window? Most of the terminal emulators have command line args to specify the size.

Another option, if you need to change it after the window appeared wmctrl might help you.

0

精彩评论

暂无评论...
验证码 换一张
取 消