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


Click here to return to the 'Easier use of X11 in bash' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Easier use of X11 in bash
Authored by: kingtrench on Nov 02, '04 06:19:14PM
Here's a different solution for getting the DISPLAY variable correctly set in Terminal.app. This will also work with Fast User Switching, when DISPLAY is not necessarily :0.0 .

1. Put X11 in your startup items (System Preferences --> Accounts --> Startup Items)

2. Copy /private/etc/X11/xinit/xinitrc to .xinitrc in your home directory.

3. Edit .xinitrc so that the last few lines are:


# Record the DISPLAY variable so other programs can discover it
echo $DISPLAY > ~/.X11_DISPLAY

# start some nice programs

#xterm &

# start the window manager

exec quartz-wm

Basically we're putting the value of the DISPLAY variable in a file so we can find it from Terminal.app. Also, since I prefer to user Terminal.app instead of xterm in X11, I've commented out the automatic startup of xterm.

4. Add these lines to your .bashrc file:


# Is X11 running?  Is this an Apple Terminal?  Then set DISPLAY.
# Warning - DISPLAY must not be clobbered in xterm, ssh, etc...
if [ "$TERM_PROGRAM" == Apple_Terminal ] && [ -f ~/.X11_DISPLAY ] ; then
    export DISPLAY=`cat ~/.X11_DISPLAY`
fi

For this to work, .bashrc must be sourced when you start a new Terminal. This has been covered in a few places already, but what I do is to add these lines to .bash_profile:


if [ -f ~/.bashrc ] ; then
        . ~/.bashrc
fi

And this line to .Xdefaults:


XTerm*.LoginShell: True


[ Reply to This | # ]
Easier use of X11 in bash
Authored by: Oops on Jan 04, '05 05:10:59PM

Thank you! Thank you! Thank you! kingtrench!

I've recently switched to bash from tcsh and have not been able to get X11 forwarding to work, whereas I was successful with it before. Your suggestions in this post provided what I needed to get it to work again. Binaries were having difficulty getting the Display.



[ Reply to This | # ]