Bash Resize Terminal Xterm
Solution 1
I don't have a Mac so I can't try this but wmctrl
is a UNIX app so it should work for OSX as well. Try something like:
wmctrl -r :ACTIVE: -e 5,-1,-1,660,540
----------- -- -- -- --- ---
| | | | | |---> Window height
| | | | |-------> Window width
| | | |-----------> Window Y coordinates
| | |--------------> Window X coordinates
| |----------------> Gravity
|--------------------------> Apply to the active window
Gravity can be one of (source):
- NorthWest (1)
- North (2),
- NorthEast (3),
- West (4),
- Center (5),
- East (6),
- SouthWest (7),
- South (8),
- SouthEast (9)
- Static (10).
A gravity of 0 indicates that the Window Manager should use the gravity specified in
WM_SIZE_HINTS.win_gravity
.
Solution 2
There is an ANSI escape sequence that most terminals (include Terminal.app) should accept:
$ echo -e "\e[8;30;60t"
This will resize your terminal to have 30 rows and 60 columns (swap the 30 and 60 if I've misunderstood the dimensions you want).
As long as this string is written to the terminal, you can use it from anywhere. You can make it part of myapp
, or create a shell function as a wrapper:
myapp () {
echo -e "\e[8;30;60t"
command myapp "$@"
}
Solution 3
You could try AppleScript. Here an example to tun vim:
#!/bin/sh
# Script runvim.sh
osascript <<EOF
tell app "Terminal"
set number of rows of first window to 34
set number of columns of first window to 96
set custom title of first window to "vim"
end tell
EOF
vim $@
This is built-in but you might have to find out how to differentiate between Terminal and iTerm2. Either you know what your users want to use or you let them pick (or something more clever :-)).
Related videos on Youtube
Blue Ice
Updated on September 18, 2022Comments
-
Blue Ice over 1 year
I am looking for a universal builtin command that resizes Xterm based terminals.
This is some sort of command that won't make a new window, that I won't need to include in the file that these terminals start up with.
I want to make an app that will open in a 60x30 frame, but only after you run the command
myapp run
I don't want my terminal to always open at 30x60, I just want it to resize when I run myapp.
-
terdon about 11 years@BlueIce You will not find a built in for this. Bash has no knowledge of the GUI, why should it?
-
HikeMike about 11 yearsThis won't work on OS X, since its Terminal app isn't based on X11.
-
Blue Ice about 11 yearsEdited question appropriately.
-
Blue Ice about 11 yearsI am looking for an xterm solution. This doesn't seem to work on xterm on linux.
-
chepner about 11 yearsOdd; it's a standard escape sequence. This is easier to type, maybe it will work better for you:
resize -s 30 60
. I think it essentially outputs the same characters given in the answer. -
Blue Ice about 11 yearsThis also doesn't seem to work. The only resize command that I've gotten to work in xterm is
xterm -geometry 30x60
, but this just opens an entirely new window with those dimensions. -
chepner about 11 yearsThe only other thing I can think of is that the
allowWindowOps
resource is set to false, anddisallowedWindowOps
contains8
orSetWinSizeChars
, which would prevent the escape sequence from working. -
Blue Ice about 11 yearsHow do I change that? When I run the
resize
command it returns that it can't run VT100 sequences. Then I triedresize -s
command, which doesn't do anything but show a script to change the size by resetting$COLUMNS
and$LINES
. I tried the script, which also doesn't do anything.