From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from euclid.skiles.gatech.edu (list@euclid.skiles.gatech.edu [130.207.146.50]) by melb.werple.net.au (8.7.5/8.7.3) with ESMTP id EAA22328 for ; Thu, 4 Apr 1996 04:51:40 +1000 (EST) Received: (from list@localhost) by euclid.skiles.gatech.edu (8.7.3/8.7.3) id NAA21003; Wed, 3 Apr 1996 13:43:47 -0500 (EST) Resent-Date: Wed, 3 Apr 1996 13:43:47 -0500 (EST) Message-Id: <9604031840.AA21918@marathon.cs.ucla.edu> To: rft@cg.tuwien.ac.at, zsh-workers@math.gatech.edu Subject: Re: ZSH: How to detect remoteness? In-Reply-To: Your message of "Wed, 03 Apr 1996 14:28:42 +0200." <9604031228.AA05668@raven.cg.tuwien.ac.at> Date: Wed, 03 Apr 1996 10:40:29 -0800 From: Eskandar Ensafi Resent-Message-ID: <"jthul2.0.585.ZRiOn"@euclid> Resent-From: zsh-workers@math.gatech.edu X-Mailing-List: archive/latest/891 X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu 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@cs.ucla.edu (ASCII, MIME, NeXT) School of Medicine http://www.cs.ucla.edu/csd-lanai/fweb/esky ------------------------------------------------------------------------------