Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: ZSH: How to detect remoteness?



Hello,

On Wed, 03 Apr 1996 14:28:42 +0200, Robert F Tobler wrote:
> [...] I want my shell to behave differently, if I am logged in
> directly at the console of a machine, or remotely. For this I would like to  
> know a condition, that tells me the 'remoteness'.
> Is this available, or could this be included (I am using 2.6-beta13)?


There are two ways:


1. Use the output of "who am i" to check for remoteness.  If you are on
   a remote terminal, the name of the host from which you ran telnet or
   rlogin will appear in parentheses as the last item:

   jupiter% who am i
   esky       pts/10       Apr  3 10:37    (pluto)

   If you are local, there will be no host name in parentheses:

   pluto% who am i
   esky       pts/3        Apr  3 10:39

   So you can use either "awk," "expr," "grep" or "sed" to check for
   the existence of a final parenthesis.  A better way would be to use
   zsh's conditional operator and avoid the overhead of calling external
   programs:

   # Check for remoteness

   if [[ `who am i` = *\) ]]
   then
     # We are remote
   else
     # We are local
   fi


2. Check the environment for variables set by your terminal emulator.  I
   noticed that your mail header contained X-Nextstep-Mailer, so if you are
   using NEXTSTEP, you can check for the varibales set by Terminal.app:
   either TERM_PROGRAM or TERM_PROGRAM_VERSION.  Under X Windows, using an
   xterm, you can check for WINDOWID.

   You should add as many tests as necessary for all the different terminal
   types you normally use.  I'm sure you know how to do this, but just in
   case, here's what you'll need in your .zlogin file or anywhere else you
   want to check for remoteness:

   # Check for remoteness under NEXTSTEP and X Windows

   if [[ ${+TERM_PROGRAM} = 0 && ${+WINDOWID} = 0 ]]
   then
     # We are remote
   else
     # We are local
   fi


I hope this helps!

- Eskandar

------------------------------------------------------------------------------
Eskandar Ensafi                              Object-Oriented Software Engineer
University of California, Los Angeles                                         
Department of Biomathematics              esky@xxxxxxxxxxx (ASCII, MIME, NeXT)
School of Medicine                  http://www.cs.ucla.edu/csd-lanai/fweb/esky
------------------------------------------------------------------------------




Messages sorted by: Reverse Date, Date, Thread, Author