zsh-users
 help / color / mirror / code / Atom feed
* showing 'talk' status in PROMPT
@ 1997-10-27  4:43 Timothy J Luoma
  1997-10-27  8:52 ` Peter Stephenson
  1997-10-28  1:28 ` Deborah Ariel Pickett
  0 siblings, 2 replies; 6+ messages in thread
From: Timothy J Luoma @ 1997-10-27  4:43 UTC (permalink / raw)
  To: zsh-users


I am using this to let me know if I have turned off messages on my terminal:

mesg () {

        case $1 in
                n*|off)
                        TALK="<notalk> "
                        /usr/bin/mesg n
                ;;

                *)
                        /usr/bin/mesg $*
                        TALK=""

                ;;
        esac
}




# note: the next line is all one line until the %b
# then another line break after the %s
PROMPT='%SUSER: %B(%n)%b HOST: %B(%M)%b TTY: %B(tty%l)%b HIST#: %B(%h)%b
[OLDPWD: %B$OLDPWD%b] [PWD: %B%~%b]%s
$TALK'

Does anyone see any problems with this, or have a better way to do this?

Thanks

TjL


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

* Re: showing 'talk' status in PROMPT
  1997-10-27  4:43 showing 'talk' status in PROMPT Timothy J Luoma
@ 1997-10-27  8:52 ` Peter Stephenson
  1997-10-27 17:18   ` Timothy J Luoma
  1997-10-27 17:21   ` Bart Schaefer
  1997-10-28  1:28 ` Deborah Ariel Pickett
  1 sibling, 2 replies; 6+ messages in thread
From: Peter Stephenson @ 1997-10-27  8:52 UTC (permalink / raw)
  To: Zsh users list

Timothy J Luoma wrote:

> I am using this to let me know if I have turned off messages on my terminal:
> 
> mesg () {
> 
>         case $1 in
>                 n*|off)
>                         TALK="<notalk> "
>                         /usr/bin/mesg n
>                 ;;
> 
>                 *)
>                         /usr/bin/mesg $*
>                         TALK=""

I haven't tried this out, but you have problems if you just run mesg
with no arguments and it was already turned off.  You should test
for '') and if so just run /usr/bin/mesg without setting $TALK.

> 
>                 ;;
>         esac
> }

-- 
Peter Stephenson <pws@ifh.de>       Tel: +49 33762 77366
WWW:  http://www.ifh.de/~pws/       Fax: +49 33762 77413
Deutsches Elektronen-Synchrotron --- Institut fuer Hochenergiephysik Zeuthen
DESY-IfH, Platanenallee 6, 15738 Zeuthen, Germany.


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

* Re: showing 'talk' status in PROMPT
  1997-10-27  8:52 ` Peter Stephenson
@ 1997-10-27 17:18   ` Timothy J Luoma
  1997-10-27 17:21   ` Bart Schaefer
  1 sibling, 0 replies; 6+ messages in thread
From: Timothy J Luoma @ 1997-10-27 17:18 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: Zsh users list

	Author:        Peter Stephenson <pws@ifh.de>
	Original-Date: Mon, 27 Oct 1997 09:52:33 +0100
	Message-ID:    <199710270852.JAA07593@hydra.ifh.de>

> I haven't tried this out, but you have problems if you just run mesg
> with no arguments and it was already turned off.  You should test
> for '') and if so just run /usr/bin/mesg without setting $TALK.

Ah yes!  Believe it or not I had ``tested'' whether 'mesg' by itself would  
work, but I had only tested it when I had messages ON!  So I never noticed  
this.

Thanks for the pointer.  The new function is as follows:

mesg () {

        case $1 in
                n*|off)
                        TALK="<notalk> "
                        /usr/bin/mesg n
                ;;

                '')
                        /usr/bin/mesg
                ;;

                *)
                        TALK=""
                        /usr/bin/mesg $*
                ;;

        esac
}

	TjL
	


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

* Re: showing 'talk' status in PROMPT
  1997-10-27  8:52 ` Peter Stephenson
  1997-10-27 17:18   ` Timothy J Luoma
@ 1997-10-27 17:21   ` Bart Schaefer
  1997-10-27 18:13     ` Andrew Main
  1 sibling, 1 reply; 6+ messages in thread
From: Bart Schaefer @ 1997-10-27 17:21 UTC (permalink / raw)
  To: Zsh users list

} Subject: Re: showing 'talk' status in PROMPT
}
} Timothy J Luoma wrote:
} 
} > I am using this to let me know if I have turned off messages on my terminal:

Peter Stephenson wrote:
} 
} I haven't tried this out, but you have problems if you just run mesg
} with no arguments and it was already turned off.  You should test
} for '') and if so just run /usr/bin/mesg without setting $TALK.

How about this:

	mesg () {
		command mesg $*
		setopt localoptions nullglob
		local tty
		tty=( ${~TTY:s/dev/de[v]/}(I) )
		case $tty in
			$TTY)
				TALK=
			;;
			'')
				TALK="<notalk> "
			;;
		esac
	}

Question:  Is there any easier way to get the (I) glob qualifier applied
to the value of $TTY ?  I had to invent that de[v] trick just to force
there to be a pattern somewhere in the string.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com


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

* Re: showing 'talk' status in PROMPT
  1997-10-27 17:21   ` Bart Schaefer
@ 1997-10-27 18:13     ` Andrew Main
  0 siblings, 0 replies; 6+ messages in thread
From: Andrew Main @ 1997-10-27 18:13 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh-users

Bart Schaefer wrote:
>		setopt localoptions nullglob
>		local tty
>		tty=( ${~TTY:s/dev/de[v]/}(I) )

local tty
tty=( ${TTY}(|)(IN) )

You must use `(|)' because `()' would be treated as a function definition.
Nevertheless, you only get one copy of the pathname.

-zefram


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

* Re: showing 'talk' status in PROMPT
  1997-10-27  4:43 showing 'talk' status in PROMPT Timothy J Luoma
  1997-10-27  8:52 ` Peter Stephenson
@ 1997-10-28  1:28 ` Deborah Ariel Pickett
  1 sibling, 0 replies; 6+ messages in thread
From: Deborah Ariel Pickett @ 1997-10-28  1:28 UTC (permalink / raw)
  To: Timothy J Luoma; +Cc: zsh-users

> I am using this to let me know if I have turned off messages on my terminal:
> mesg () {
...
> }
> Does anyone see any problems with this, or have a better way to do this?

I do this by rather a different way.  Every so often, I check the status
of my TTY to see whether it has write access granted to others.  I
figure that I don't type 'mesg' very often, so checking every minute or
so isn't much of a performance loss.

I wanted to be able to just do something like 'mesg >/dev/null' to use
the exit status of mesg to determing if messages are on or not without
cluttering up my screen with "is n" or "is y".  But the writers of mesg
on Ultrix in all their wisdom, printed the message to stderr, and also
used stderr as the tty to check.  So it just couldn't work.

I finally wrote a tiny perl script to do it:

#!/usr/monash/bin/perl
# Return y or n based on whether others can write to our tty.
# usage: mesg-status $TTY
if ((stat($ARGV[0]))[2] & 022)
{
  print "y\n";
}
else
{
  print "n\n";
}

so I just invoke this every now and again and insert it into my prompt
in the usual ways.

Granted, it isn't as efficient as the rewriting of the mesg function,
but I suppose it makes up for that by always being correct, if, say,
something else tries to change the status of my tty.

-- 
Debbie Pickett  http://www.cs.monash.edu.au/~debbiep/  tlm@yoyo.cc.monash.edu.au
"Long and wide, eternity from side to side, lead me through the rapids, guide me
 to the shore. There's a place that's far beyond this time and space, when each
  of us comes face to face with something more." - _Siren Song_, Alan Parsons


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

end of thread, other threads:[~1997-10-28  1:36 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-10-27  4:43 showing 'talk' status in PROMPT Timothy J Luoma
1997-10-27  8:52 ` Peter Stephenson
1997-10-27 17:18   ` Timothy J Luoma
1997-10-27 17:21   ` Bart Schaefer
1997-10-27 18:13     ` Andrew Main
1997-10-28  1:28 ` Deborah Ariel Pickett

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