7

I want to execute a command in a bash script that will resize the terminal window. In xterm

xterm -geometry=30x30

will create a new xterm window, and

lxterminal --geometry=30x30

will create a new lxterminal window.

Is there a way to resize either terminal without opening a new window? This is what it would look like:

if [ $TERMINALTYPE=xterm ]; then
    DASH="-"
else
    DASH="--"
endif

echo -e $TERMINALTYPE" "$DASH"geometry 30x30"

BUT: If there is a command that is a nice one-liner that will work with either terminal (vt100 escape sequence maybe) then that is even better.

5
  • If you have Lubuntu, why don't you edit ~/.config/openbox/lubuntu-rc.xml instead of this scripting route?
    – user25656
    Mar 31, 2013 at 4:39
  • @vasa1 I am running a script that will change the window to be the right size because it is an app. I don't want it to open like this every time, just when I run the app.
    – Blue Ice
    Mar 31, 2013 at 4:46
  • Modifying the file I mentioned will let you change the size of the existing active window to whatever dimensions you wish whenever you wish. You do so by pressing a couple of keys such as Super+up arrow or whatever. Other times, your window size will remain the default.
    – user25656
    Mar 31, 2013 at 4:49
  • Have you looked into resizing your window with wmctrl yet? It's a CL tool that directly communicates with your window manager and works for all applications. Here are some examples of its usage. Mar 31, 2013 at 7:09
  • @MHC Yes. I am looking for a builtin xterm resizing command.
    – Blue Ice
    Mar 31, 2013 at 19:24

3 Answers 3

7

There are two steps to this. First, you need to tell xterm to allow it to happen at all, because by default it ignores requests by hosted programs to resize the window. Add this to your ~/.Xdefaults:

xterm*allowWindowOps: true

For this to take effect, you either have to log out, or run:

xrdb ~/.Xdefaults

Then launch a new xterm, and in your bash script:

echo -ne "\e[8;30;30t"
1
4

Just want to share:

apt-get install xterm

Use the following resize command where 20 = no of rows, 40 = no of columns:

resize -s 20 40

Change the value of rows and columns as per requirement.

1

In addition to @Paul's correct answer:

You could try this without editing ~/.Xdefaults, by running:

xterm -xrm 'xterm*allowWindowOps: true'

Then, in new window:

printf "\e[8;%d;%dt" $[LINES+5] $[COLUMNS+5]

.Xdefaults or .Xresources

Depending on your installation, you may have to store this on .Xresources instead of .Xdefaults.

FILES

Xrdb does not load any files on its own, but many desktop environments use xrdb to load ~/.Xresources files on session startup to initialize the resource database, as a generalized replacement for ~/.Xdefaults files.

Then after

sed -e '$axterm*allowWindowOps: true' -i.bak .Xresources 
xrdb <.Xresources

Then...

Some bind samples

You could run this or add to your .bashrc:

# Some bind for 'Shift' + <direction> key and allowWindowOps resource
bind -x '"\e[1;2C"':'printf  "\e[8;%d;%dt" $LINES $((COLUMNS+5))'
bind -x '"\e[1;2D"':'printf  "\e[8;%d;%dt" $LINES $((COLUMNS-5))'
bind -x '"\e[1;2B"':'printf  "\e[8;%d;%dt" $((LINES+3)) $COLUMNS'
bind -x '"\e[1;2A"':'printf  "\e[8;%d;%dt" $((LINES-3)) $COLUMNS'

to be used with respectively: Shift+Right   ,   Shift+Left   ,   Shift+Down   or   Shift+Up

Note: As this in bind, this will work in interactive command environment (aka not under vim nor less, read or any work in progress)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .