From: "Bart Schaefer" <schaefer@candle.brasslantern.com>
To: zsh-users@sunsite.dk
Subject: Re: Differrent prompt for remote machines
Date: Sat, 31 Mar 2001 19:14:49 +0000 [thread overview]
Message-ID: <1010331191449.ZM8000@candle.brasslantern.com> (raw)
In-Reply-To: <E14jJc8-0002oE-00@crucigera.fysh.org>
On Mar 31, 12:32pm, Zefram wrote:
} Subject: Re: Differrent prompt for remote machines
}
} Dominik Vogt wrote:
} > Basically it breaks down to detecting if the shell runs on a
} > local terminal or through a network connection.
}
} if [[ $TTY == /dev/pts/* || $TTY == /dev/tty[a-z]* ]]; then
} PS1='%n@%m> '
} else
} PS1='%n> '
} fi
That doesn't work when X11 is involved, because all X terminal emulators
appear to be running "through a network connection" even when they're on
the local machine.
As it turns out, I've been trying to solve a similar problem for another
reason (I'll resist the urge to bore you with details) and came up with
the solution below.
One remaining issue is that if you're on a university timesharing system
or the like, you're probably on /dev/tty[a-z]* even if you're just using
an ancient vt100 in the lab; but even then it should be possible to come
up with a test for "is this shell on a pseudo-terminal".
The `|| ps -lp' is for systems that insist on a leading `-' in the `ps'
options (and therefore probably don't have `w'). Maybe that's overkill.
It should be obvious that this is meant to be a shell function.
---- 8< ---- snip ---- 8< ----
emulate -L zsh
local h ps ppid=$PPID
while (( ppid > 1 ))
do
ps=("${(f)$(ps lwp$ppid 2>/dev/null || ps -lp$ppid)}")
h=($=ps[1])
ps=($=ps[2])
case "$ps" in
*sshd*)
# Shell running from ssh, probably not the local machine
PS1='%n@%m> '
break
;;
*(xterm|rxvt|dtterm|eterm|gnoterm|emacs)*)
# Shell running from an emulator, check for local displays
if [[ -n $SSH_CLIENT ]]
then
# Emulator started from ssh, probably port-forwarding
PS1='%n@%m> '
break
elif [[ $DISPLAY = ($HOST*|):* && ${HOSTDISPLAY:-$HOST} = $HOST* ]]
then
# Shell running on a local display (though could be VNC)
PS1='%n> '
break
elif [[ -n $DISPLAY ]]
then
# Shell running on a remote display
PS1='%n@%m> '
break
else
# Probably running inside a text-mode emacs
fi
;;
*login*)
# Shell running on the local console, or from rlogin or telnet
if [[ $TTY == /dev/pts/* || $TTY == /dev/tty[A-Za-z]* ]]
then
# Shell running from rlogin or telnet
PS1='%n@%m> '
else
# Shell running on local console
PS1='%n> '
fi
break
;;
*)
# Shell running from su or from some other shell or program
if [[ -n $SSH_CLIENT ]]
then
# Some ancestor is ssh, probably not local
PS1='%n@%m> '
break
fi
;;
esac
# Not enough information yet, climb the process tree
ppid=${ps[$h[(i)PPID]]:-1}
done
---- 8< ---- snip ---- 8< ----
--
Bart Schaefer Brass Lantern Enterprises
http://www.well.com/user/barts http://www.brasslantern.com
Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net
next prev parent reply other threads:[~2001-03-31 19:16 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-03-30 9:42 Dominik Vogt
2001-03-30 9:59 ` Andrej Borsenkow
2001-03-30 10:48 ` Dominik Vogt
2001-03-30 15:55 ` Bart Schaefer
2001-03-31 11:32 ` Zefram
2001-03-31 18:26 ` Stephane Bortzmeyer
2001-03-31 19:14 ` Bart Schaefer [this message]
2001-04-01 3:53 ` E. Jay Berkenbilt
2001-04-01 4:41 ` Bart Schaefer
2001-03-31 18:26 ` Stephane Bortzmeyer
2001-04-04 17:21 ` Dominik Vogt
2001-04-02 20:46 ` Matt Pharr
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1010331191449.ZM8000@candle.brasslantern.com \
--to=schaefer@candle.brasslantern.com \
--cc=zsh-users@sunsite.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).