[vox-tech] bash question

vox-tech@lists.lugod.org vox-tech@lists.lugod.org
Mon, 6 May 2002 16:12:12 -0400


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