Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Set xterm dimensions using Apple's X11 terminal UNIX
I'd been looking to replace my use of terminal.app with X11/xterm, since I often find my self running X11 apps on remote hosts. But I couldn't find a preference to set the xterm dimensions -- I'm used to a minimum of 132 columns and manually resizing the xterm window at each launch finally drove me to find out how to do it. Launch X11, then select Applications -> Customize. The X11 Application Menu should have an entry something like:
Terminal     |     xterm     |     n
Double-click the xterm command field and simply add the -geometry parameter. The following will set 132 columns x 50 rows for the initial and subsequent xterms:
 xterm -geometry 132x50 
You can read about other parameters for xterm in the man page from within xterm itself via man xterm.
    •    
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[13,200 views]  

Set xterm dimensions using Apple's X11 terminal | 18 comments | Create New Account
Click here to return to the 'Set xterm dimensions using Apple's X11 terminal' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Set xterm dimensions using Apple's X11 terminal
Authored by: merlyn on Mar 09, '04 11:04:30AM
I've had things like this in my app menu for a long time. To log in to my mail/webserver:

xterm -geometry 80x60 -T blue -e ssh -t blue.stonehenge.comm screen -DR
To make a local terminal without a scrollbar:

xterm -geometry 80x48 -T terminal
To make a local terminal with a scrollbar:

xterm -geometry 80x48 -sb -rightbar -sl 1024
To run ethereal with root privs (so I can use promisc mode):

sudo /sw/bin/ethereal


[ Reply to This | # ]
Set xterm dimensions using Apple's X11 terminal
Authored by: acnguyen on Mar 09, '04 11:12:43AM
Another way to set geometry (and other X defaults) is to create/modify your .Xdefaults file in your home directory.

Add a line like:

 XTerm*geometry: 132x50


[ Reply to This | # ]
Set xterm dimensions using Apple's X11 terminal
Authored by: mzs on Mar 09, '04 11:35:09AM
Yes an .Xresources file is the way to go. That way if you type 'xterm &' in one xterm to get another one instead of using the menu, the new xterm will have the correct dimensions as well.

Just be sure that /usr/bin/cpp exists on your system. The .Xresources file is run through the preprocessor by default and this will not work if the preprocessor is not installed on your system. You need to install the BSD SDK from the DevTools in order to have /usr/bin/cpp on your system.

Some other lines I have in my .Xresources are:

XTerm*scrollBar: on

XTerm*saveLines: 50000

XTerm*rightScrollBar: true

You can do a 'man xterm' from the xterm to see all the resources you can set. This is generally true for all X11 apps as well, so if you want to set things for others, just add the appropriate resource settings in the .Xresource file.

I made this post that explains some more about X11 resources.

As a side note, if you are using xterm instead of Termial.app, you may like xman rather than man. Just do 'xman &' from the xterm and then you can search and browse man pages with mouse clicks and dialog boxes.

[ Reply to This | # ]

use .Xresources
Authored by: mzs on Mar 09, '04 12:09:14PM
I just noticed that your post told to use .Xdefaults. You should not do that anymore, it became obsolete with X11R5 if I recall correctly.

There is a difference between .Xdefaults and .Xresources. The .Xresources file is sourced when the X11 server starts (usually from an .xsession, but the system defaults do this even if you do not have a .xsession file in your home dir). The .Xdefaults are read whenever any X11 application starts. That is nice of course, but unfortunately the .Xdefaults file does not work any longer by default. With modern X11 servers the file that is sourced upon start-up of all X11 applications is now .Xdefaults-hostname instead.

The thing is that there is an environment variable XENVIRONMENT which is used to over-ride that. Some systems do the equivalent of setenv XENVIRONMENT $HOME/.Xdefaults so that an .Xdefaults file in the home directory still works, but I do not think the default setup of X11 on MacOS X does anything like this.

If you want your .Xresources file to take effect immediately without having to restart the X11 server, just do a xrdb -merge $HOME/.Xresources from an xterm after modifying the file.

I hope this comment helps and does not cause too much confusion.

[ Reply to This | # ]

use .Xresources
Authored by: adrianm on Mar 09, '04 02:37:37PM

X11 with 10.3.2 uses .Xdefaults just fine.
Did with 10.2.8 too.



[ Reply to This | # ]
use .Xresources
Authored by: mzs on Mar 09, '04 03:19:18PM
X11 with 10.3.2 uses .Xdefaults just fine. Did with 10.2.8 too.

Yes until you have an .Xresources file. (set-up that way for backwards comaptibility) If you have both then the settings in your .Xdefaults never take, because Xlib looks for .Xdefaults-hostname unless you set the XRESOURCES environment variable to point to .Xdefaults instead. Try it, then you will believe me. (Make sure that hostname is the full output of uname -n.)

Because of all this wierdness, it is a good idea to just use the .Xresources file instead of .Xdefaults. This way if you ever create an .Xresources file, you will not wonder why your settings in .Xdefaults are not taking any longer. If you ever create your own .xsession, be sure to load the resources in the system xresources file and the .Xresources file in your home dir.

[ Reply to This | # ]

use .Xresources
Authored by: Graff on Mar 09, '04 10:34:47PM

Ok, I created a working .Xdefaults but I had a problem with the .Xresources file. I renamed the .Xdefaults to .Xresources after I saw that it was working. When I tried to open an xterm in X11.app with the command "xterm &", the window opened up without any of my settings.

I did the xrdb command that you suggested and then I was able to open a window with my settings. However when I quit X11.app and restarted it I only got plain windows without any of my settings. I again did the xrdb command and as long as I didn't quit X11.app was able to open windows with my settings.

Any ideas?



[ Reply to This | # ]
use .Xresources
Authored by: mzs on Mar 10, '04 09:16:05AM

Do the following in your home dir.

verify that there is no .Xdefaults
create .Xresources with the resources that you like
verify that there is no .xsession file in your home dir

(you can verify with this command: file .Xdefaults .xsession)

Now quit X11 and start it again. It should work now. .Xresources will only take on a restart of X11, that is why you can do the xrdb command.

If that does not work, post a comment with the output of:

/bin/tcsh -c 'setenv'

(even if you are using bash, then this will give only the 'exported' vars)

Also as a sanity check, do:

ls -l $HOME/.Xresources

Maybe the permissions need to look like this: -rw-r--r--

Also do:

ls -l /usr/bin/cpp

This is used by X11 when your .Xresources file is sourced. (to handle comments and includes)

I am sort of grasping for straws by this point, but I hope there is some silly thing wrong this will find.



[ Reply to This | # ]
use .Xresources
Authored by: mzs on Mar 10, '04 09:24:55AM

One more thing, do you have an .xinitrc file in your home dir? You should not. That is supposed to be used in cases where you use a command like startx to start the X11 server and your window manager. You might have such a file and it may not source your .Xresources file. In fact you might do this command in your home dir and post the output:

ls -dl .[Xx]*



[ Reply to This | # ]
use .Xresources
Authored by: Graff on Mar 10, '04 08:53:48PM

Yep, that must be it. I have an .xinitrc file. I thought that this was needed for X11.app in order for it to use the quartz-wm window manager. This is what I have in that file:

xterm &
exec quartz-wm

Can I just remove the .xinitrc file or should I add in the xrdb command to "source" the .XResources file?

Hmm, I just tried removing the .xinitrc file and now the .XResources file works fine. I think that I had added a .xinitrc file in order to start up with a formatted X11 window. I used to have this code in there before I changed over to having a .XResources file:

xterm -rightbar -sb -sl 2000 -geometry 100x40 -bg black -fg white -fa Monaco -fs 11 &
exec quartz-wm


[ Reply to This | # ]
use .Xresources
Authored by: mzs on Mar 11, '04 09:34:34AM
I am happy I was able to help. If you like what the default starts for you, then you have no need for an .xinitrc file. If you really wish to change it, you can try creating an .xsession file in your home dir. (.xsession is intended for something like xdm plus xsm while .xinitrc is intended for something like startx. startx or somehting similar would be a script that assumes a terminal and can prompt the user asking things like which window manager to start, this is not how X11 is started on MacOS X so the .xsession file makes more sense.) .xsession is a script that takes no args and it should begin on the first line:

#!/bin/sh

It should be executable as well. It depends what the scripts on your system are like how it is started-up so to be safe on all systems you should always put the bourne shell shebang as the first line, make it executable, and assume that it is sourced by sh. On X11 by default is is started by part of a script that looks like this but these scripts do change from version to version:

#  The startup script is not intended to have arguments.

startup=$HOME/.xsession
resources=$HOME/.Xresources

if [ -s "$startup" ]; then
        if [ -x "$startup" ]; then
                exec "$startup"
        else
                exec /bin/sh "$startup"
        fi
...
fi

In your .xsession script you would like to have something like this:

resources=$HOME/.Xresources

if [ -r "$resources" ]; then
        xrdb -load "$resources"
fi

You may like to do -merge instead in case you have created some Xresources under /etc/X* or /usr/X* that you like to use but by now people should be using app-defaults instead.

After this you could have some lines like you had in the parent comment. Alternatively you might just have it start xsm. Do a man xsm in an xterm to see what that does and how to configure it.

So as you can see there is a LOT of detail to making good .xsession/.xinitrc files. I had to do it in the past when I had a networked home directory and several machines that I would run X sessions on with some having more or less heads (monitors). I have not done any of this compicated scripting on MacOS X though, so I have no idea what sort of gotcha's you might run into. I would just avoid as much of this as possible.

[ Reply to This | # ]

Set xterm dimensions using Apple's X11 terminal
Authored by: Graff on Mar 09, '04 11:39:50AM

Here are my usual settings for a terminal window:
xterm -rightbar -sb -sl 2000 -geometry 100x40 -bg black -fg white -fa Monaco -fs 11

This command tells xterm to put the scrollbar on the right, keep a scroll buffer, make it hold 2000 lines, make the window 100 wide by 40 long, make the background black and the foreground (text) white, use Monaco at 11 point.



[ Reply to This | # ]
Set xterm dimensions using Apple's X11 terminal
Authored by: vancenase on Mar 09, '04 01:40:17PM

how do you get the scrollbar to actually scroll when you put your mouse cursor over it and it makes an arrow? i could never get it to work, unless it's purely for looks.



[ Reply to This | # ]
Set xterm dimensions using Apple's X11 terminal
Authored by: adrianm on Mar 09, '04 02:41:09PM

It uses a different mouse interface to Mac OS X native windowing system (or indeed almost any other).

Click the left mouse button on scroll bar to scroll down, right to scroll up and middle button to scroll 'here'.

If you don't have a multi-button mouse, you can probably fiddle with certain xdefaults, but if that's the case you're probably better off with Terminal.



[ Reply to This | # ]
Set xterm dimensions using Apple's X11 terminal
Authored by: mzs on Mar 09, '04 02:54:39PM

There is a bit more to this. The farther down the scrollbar you click, the farther it scrolls, click near the top and it scrolls only a single line. Also with the 'here' scroll, if you hold down the mouse button while dragging in the scrollbar, it drags the view around. You can simulate the second and third mouse buttons with the prop and opt keys if you set the X11 prefs appropriately. If you do not want to use the mouse for scrolling, then Shift+PageUp and Shift+PageDown scroll half pages.



[ Reply to This | # ]
Set xterm dimensions using Apple's X11 terminal
Authored by: mweissen on Mar 09, '04 05:28:30PM

You can do this live using the resize command:

eval `resize -s 25 132`

It works in xterm as well as Terminal.app.



[ Reply to This | # ]
with ssh, there's no need to use Apple's X11 terminal
Authored by: shemp9999 on Mar 09, '04 10:00:34PM

i use ssh tunnels to log onto remote machines and can log on and execute X11 apps using apple's terminal.app, as long as X11 is running. (panther 10.3.2)

if X11 is not running and i try to connect terminal.app returns this at login:

"Warning: No xauth data; using fake authentication data for X11 forwarding."

otherwise if X11 is up when i log in, it just works. no need to use that fugly xterm.



[ Reply to This | # ]
with ssh, there's no need to use Apple's X11 terminal
Authored by: Lizard_King on Mar 10, '04 05:04:33PM

To clarify for others not familiar with forwarding X applications: the reason why you must have X11 running, is that when you are forwarding X applications though ssh, you are required to have an X Server running on the machine you would like to see the application's interface (usually the machine you are sitting at).

X11.app is an X Server. Terminal.app is not.

xterm is simply another X application (which has terminal functionality similar to Terminal.app) that you can run within your X Server environment. Terminal.app is an application that Apple built that provides terminal functionality, but runs native to the OS X operation system.



[ Reply to This | # ]