zsh-users
 help / color / mirror / code / Atom feed
* Dynamically adding to $mailpath?
@ 2002-12-19 11:22 Aidan Kehoe
  2002-12-19 11:41 ` Phil Pennock
  2002-12-19 11:42 ` Borzenkov Andrey
  0 siblings, 2 replies; 6+ messages in thread
From: Aidan Kehoe @ 2002-12-19 11:22 UTC (permalink / raw)
  To: zsh-users


Hiya, 

Should this; 

  typeset -a mailpath
  for i in ~/mail/*.spool; do 
    set $mailpath[$#mailpath+1]="${i}?You have new mail in $(basename $i .spool)."; 
  done

have worked? I got around it by using $MAILPATH, but 

  zsh: /home/hcksplat/mail/X.spool?You have new mail in X. not found
  $ 

doesn't seem right to me. ZSH_VERSION=4.0.4, setopt gives nobeep,
correct, noglobalrcs, histignoredups, histignorespace, interactive,
monitor, shinstdin.

Thanks, 

	Aidan Kehoe
-- 
It's time to put on makeup/It's time to dress up right,
It's time to raise the curtain on the Muppet Show tonight,


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

* Re: Dynamically adding to $mailpath?
  2002-12-19 11:22 Dynamically adding to $mailpath? Aidan Kehoe
@ 2002-12-19 11:41 ` Phil Pennock
  2002-12-19 11:42 ` Borzenkov Andrey
  1 sibling, 0 replies; 6+ messages in thread
From: Phil Pennock @ 2002-12-19 11:41 UTC (permalink / raw)
  To: Aidan Kehoe; +Cc: zsh-users

On 2002-12-19 at 11:22 +0000, Aidan Kehoe wrote:

>   for i in ~/mail/*.spool; do 
>     set $mailpath[$#mailpath+1]="${i}?You have new mail in $(basename $i .spool)."; 
>   done
> 
> have worked? I got around it by using $MAILPATH, but 

No, since you set a variable using its name without a $ beforehand.  I
have this problem too, when I've been writing too much Perl.

For some reason, the "set" there means that the array part isn't in
arithmetic context, in fact the rest is not evaluated properly, but is
instead treated as one string (or two, with s/=/ /) and put into ARGV.
Since "z" is at the end of the alphabet:
% print -l $@
mailpath[0+1]=/home/phil/Mail/Lists/zsh?You have new mail in zsh.
%

Lose the "set $" and it works for me, after changing to my set-up.  And
one optimisation, dropping the subshell ...

typeset -a mailpath
for i in ~/Mail/Lists/*(.); do
 mailpath[$#mailpath+1]="${i}?You have new mail in ${i:t}."
done

-- 
"We've got a patent on the conquering of a country through the use of force.
 We believe in world peace through extortionate license fees." -- Andy Forster


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

* RE: Dynamically adding to $mailpath?
  2002-12-19 11:22 Dynamically adding to $mailpath? Aidan Kehoe
  2002-12-19 11:41 ` Phil Pennock
@ 2002-12-19 11:42 ` Borzenkov Andrey
  2002-12-19 12:03   ` Aidan Kehoe
  2002-12-19 12:47   ` Phil Pennock
  1 sibling, 2 replies; 6+ messages in thread
From: Borzenkov Andrey @ 2002-12-19 11:42 UTC (permalink / raw)
  To: 'Aidan Kehoe', zsh-users


> Should this;
> 
>   typeset -a mailpath
>   for i in ~/mail/*.spool; do
>     set $mailpath[$#mailpath+1]="${i}?You have new mail in $(basename $i
> .spool).";
>   done
> 
> have worked? 

No; 

1. $mailpath[$#mailpath+1] is evaluated before even trying to execute
anyting so the above is the same as

set ="{i}..."

2. set foo[bar] is wrong for setting any variable anyway

3. you do not need basename in zsh, it does it internally.


I got around it by using $MAILPATH, but
> 
>   zsh: /home/hcksplat/mail/X.spool?You have new mail in X. not found
>   $
> 
> doesn't seem right to me. ZSH_VERSION=4.0.4, setopt gives nobeep,
> correct, noglobalrcs, histignoredups, histignorespace, interactive,
> monitor, shinstdin.
> 

mailpath=((${$(echo ~/mail/*.spool(N))//(#m)*/$MATCH?You have new mail in
${MATCH:r:t}}))

should work though. Unfortunately you still need one fork (echo) unless I
miss some obvious way to treat result of nested globbing as array.

-andrey


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

* RE: Dynamically adding to $mailpath?
  2002-12-19 11:42 ` Borzenkov Andrey
@ 2002-12-19 12:03   ` Aidan Kehoe
  2002-12-19 12:30     ` Borzenkov Andrey
  2002-12-19 12:47   ` Phil Pennock
  1 sibling, 1 reply; 6+ messages in thread
From: Aidan Kehoe @ 2002-12-19 12:03 UTC (permalink / raw)
  To: zsh-users


 Ar an 19ú lá de mí 12, scríobh Borzenkov Andrey :

 > 1. $mailpath[$#mailpath+1] is evaluated before even trying to execute
 > anyting so the above is the same as
 > 
 > set ="{i}..."

 > 2. set foo[bar] is wrong for setting any variable anyway

D'oh. As Phil put it, too much Perl. 

 > 3. you do not need basename in zsh, it does it internally.

:-) Yeah, but I never came accross it in the docs, and basename works
in sh. 

 > mailpath=((${$(echo ~/mail/*.spool(N))//(#m)*/$MATCH?You have new mail in
 > ${MATCH:r:t}}))
 > 
 > should work though. Unfortunately you still need one fork (echo) unless I
 > miss some obvious way to treat result of nested globbing as array.

The echo is built-in, isn't it?

-- 
It's time to put on makeup/It's time to dress up right,
It's time to raise the curtain on the Muppet Show tonight,


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

* RE: Dynamically adding to $mailpath?
  2002-12-19 12:03   ` Aidan Kehoe
@ 2002-12-19 12:30     ` Borzenkov Andrey
  0 siblings, 0 replies; 6+ messages in thread
From: Borzenkov Andrey @ 2002-12-19 12:30 UTC (permalink / raw)
  To: 'Aidan Kehoe', zsh-users


>  > should work though. Unfortunately you still need one fork (echo) unless
> I
>  > miss some obvious way to treat result of nested globbing as array.
> 
> The echo is built-in, isn't it?
> 

Yes but you can't "read output of process" without forking this process. The
only case when $(...) is not forked is $(<file-name) which is replaced by
the content of file-name.

OTOH you are going to do it just once on startup, are not you? In which case
fork or not fork is irrelevant here. 

-andrey 


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

* Re: Dynamically adding to $mailpath?
  2002-12-19 11:42 ` Borzenkov Andrey
  2002-12-19 12:03   ` Aidan Kehoe
@ 2002-12-19 12:47   ` Phil Pennock
  1 sibling, 0 replies; 6+ messages in thread
From: Phil Pennock @ 2002-12-19 12:47 UTC (permalink / raw)
  To: Borzenkov Andrey; +Cc: 'Aidan Kehoe', zsh-users

On 2002-12-19 at 14:42 +0300, Borzenkov Andrey wrote:
> mailpath=((${$(echo ~/mail/*.spool(N))//(#m)*/$MATCH?You have new mail in
> ${MATCH:r:t}}))
> 
> should work though. Unfortunately you still need one fork (echo) unless I
> miss some obvious way to treat result of nested globbing as array.

What I myself actually do is use a couple of temporary variables.

	set -A _foo ~/Mail/Lists/*~*.lock(.) # not D -- don't check .meta etc
	set -A _bar ~/Maildir/.*(/)
	mailpath=( ${MAIL}
                ~/Maildir?"New mail in ~/Maildir"
		"${^_bar[@]//(#m).*/$MATCH?New mail in $MATCH}"
		"${^_foo[@]//(#m)*/$MATCH?You have new mail in ${MATCH:t}}" )
	unset _foo _bar

-- 
"We've got a patent on the conquering of a country through the use of force.
 We believe in world peace through extortionate license fees." -- Andy Forster


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

end of thread, other threads:[~2002-12-19 12:47 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-12-19 11:22 Dynamically adding to $mailpath? Aidan Kehoe
2002-12-19 11:41 ` Phil Pennock
2002-12-19 11:42 ` Borzenkov Andrey
2002-12-19 12:03   ` Aidan Kehoe
2002-12-19 12:30     ` Borzenkov Andrey
2002-12-19 12:47   ` Phil Pennock

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