zsh-workers
 help / color / mirror / code / Atom feed
* ZSH: How to detect remoteness?
@ 1996-04-03 12:28 Robert F Tobler
  1996-04-03 18:40 ` Eskandar Ensafi
  1996-04-09 17:25 ` Timothy J. Luoma
  0 siblings, 2 replies; 3+ messages in thread
From: Robert F Tobler @ 1996-04-03 12:28 UTC (permalink / raw)
  To: zsh-workers


I am just switching to zsh, and I find it really great! Thanks, for giving  
such a nice shell to the public!

I have, however, a small question, which I couldn't answer by searching the  
Manuals and the FAQ: 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)?

Thanks in advance for any help. Please mail the answer directly to me.

Robert F. Tobler

------------------------------------------------------------------------
  Robert F. Tobler                 -  tel:+43(1)58801-4585,fax:5874932
  Institute of Computer Graphics   -  mailto:rft@cg.tuwien.ac.at
  Vienna University of Technology  -  http://www.cg.tuwien.ac.at/~rft/
------------------------------------------------------------------------



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: ZSH: How to detect remoteness?
  1996-04-03 12:28 ZSH: How to detect remoteness? Robert F Tobler
@ 1996-04-03 18:40 ` Eskandar Ensafi
  1996-04-09 17:25 ` Timothy J. Luoma
  1 sibling, 0 replies; 3+ messages in thread
From: Eskandar Ensafi @ 1996-04-03 18:40 UTC (permalink / raw)
  To: rft, zsh-workers


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
------------------------------------------------------------------------------



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: ZSH: How to detect remoteness?
  1996-04-03 12:28 ZSH: How to detect remoteness? Robert F Tobler
  1996-04-03 18:40 ` Eskandar Ensafi
@ 1996-04-09 17:25 ` Timothy J. Luoma
  1 sibling, 0 replies; 3+ messages in thread
From: Timothy J. Luoma @ 1996-04-09 17:25 UTC (permalink / raw)
  To: rft; +Cc: zsh-workers


I am also using NeXTStep, and zsh (obviously ;-)

I have recently devised this as a (foolproof?) way to check to see if you
are local or remotely logged in:

This goes at the top of my .zshenv

APPNAME=`/bin/ps -axlcw | awk '{ pid=$3; ppid[pid]=$4; \
name[pid]=$NF; } END { pid='$$';\
while (name[pid]==name[ppid[pid]]) pid=ppid[pid]; \
print name[ppid[pid]]; }'`

case $APPNAME in
	telnetd)
		# do stuff for telnet login
	;;

	rshd)
		# do stuff (or nothing) for rsh
	;;

	inetd)
		# if you use RBrowser.app for NeXTStep
	;;

	Terminal|Stuart)
		# this probably means you are on console
	;;

	*)
		# dunno how you'd get here
	;;

Actually, I have mine setup so that if it isn't rshd/telnetd/inetd then
assume I am on console...

Ohh.. you may want to check for 'ftpd' also.... I hadn't thought about
that before...

Let me know if you need any help with this.

TjL

--
Timothy J. Luoma 	<luomat@capitalist.princeton.edu>
USENET: Please CC this address on replies to my posts, things vanish fast.
NeXT Info available via email! 	Send message with SUBJECT 'send info'
>>>> Please: No NeXTMail, use MIME for attachments <<<<





^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1996-04-09 17:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-04-03 12:28 ZSH: How to detect remoteness? Robert F Tobler
1996-04-03 18:40 ` Eskandar Ensafi
1996-04-09 17:25 ` Timothy J. Luoma

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).