l i n u x - u s e r s - g r o u p - o f - d a v i s
L U G O D
 
Next Meeting:
September 2: Social gathering
Next Installfest:
TBD
Latest News:
Aug. 18: Discounts to "Velocity" in NY; come to tonight's "Photography" talk
Page last updated:
2002 May 06 13:17

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
Re: [vox-tech] bash question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [vox-tech] bash question



Pete,

  I agree with Matt, $DISPLAY is what you want to check if you are asking
"am I in X windows?"... however I would suggest changing the command to the
following:

    shopt -s checkwinsize

    if [ -n "${DISPLAY}" ]; then
      xmodmap -e "remove Lock = Caps_Lock"
    fi

  The reason is checkwinsize can effect non-x windows bash sessions.  An
easy example is bash running inside a screen session can have the terminal
resized.
  The second reason is shopt commands only effect the current running 
copy of bash.  If you run bash inside you will not have those options 
take effect.  A quick example of why you would run bash a second time
is if you intend to modify the environment or ulimit and want to be able
to "backout" the change without needing to logout (or close and reopen 
the window).

> On Mon, May 06, 2002 at 07:55:42AM -0700, Peter Jay Salzman wrote:
> > how can i test for "if this shell is being run from X server running on
> > a THIS machine"?

  A simple partial answer is to check for a "simple" display variable
(without hostname component) if it doesn't mention a hostname then it 
is a local connection, (this complicated if is just looking for $DISPLAY 
matching the following perl re: "^:\d+$").

     if ! echo $DISPLAY | awk '/^:[0-9]+$/ { exit 1 }'; then
       xmodmap -e "remove Lock = Caps_Lock"
     fi

  This is operating under the expectation that if the display has a host
name component then you have come in over ssh (because ssh sets the DISPLAY
to hostname:display_number) or you manually exported the DISPLAY to a 
remote hostname.  In reality there is no reason why startx or [xgk]dm
can't set the display for a local session to "localhost:0", or "hostname:0",
but in my own testing they just don't...

    Let me know if this works out,
      Mike

  I vaguely remember DISPLAY's with '.' in them... so if you display looks
like ':0.1' you will have to change to /^:[0-9.]+$/ ...


On Mon, May 06, 2002 at 08:11:59AM -0700, Matt Roper wrote:
> If you aren't using X forwarding (i.e. ssh -X), I think you could check
> to see if $DISPLAY is set...
> 
>     if [ "${DISPLAY}" != "" ]; then
>        shopt -s checkwinsize
>        xmodmap -e "remove Lock = Caps_Lock"
>     fi
> 
> On Mon, May 06, 2002 at 07:55:42AM -0700, Peter Jay Salzman wrote:
> >    if [ "${TERM}" == "xterm" ]; then
> >       shopt -s checkwinsize
> >       xmodmap -e "remove Lock = Caps_Lock"
> >    fi
_______________________________________________
vox-tech mailing list
vox-tech@lists.lugod.org
http://lists.lugod.org/mailman/listinfo/vox-tech



LinkedIn
LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
facebook
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
O'Reilly and Associates
For numerous book donations.