Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Redirection and Variables



Nikolai Weibull wrote:
> A couple of questions:
> 
> Is this the simplest way to do the following?
> 
> local -A http_programs https_programs mailto_programs ftp_programs
> 
> http_programs=(xw "/usr/bin/firefox -remote 'openURL(%s, new-tab)'"
>                xt "/usr/bin/elinks '%s'")
> http_programs=(xw "/usr/bin/firefox -remote 'openURL(%s, new-tab)'"
>                xt "/usr/bin/elinks '%s'")
> mailto_programs=(xt "/usr/bin/mutt '%s'")
> ftp_programs=(xt "/usr/bin/lftp")
> 
> lookup () {
>   echo "${(P)$(echo ${1}_programs\[xw\])}"
> }

Using eval would be nicer than the $(...), but actually there's a hack
to avoid even that:

lookup() {
  echo ${(P)${:-$1_programs[xw]}}
}

The empty nested substitution always returns the string after the :-,
which undergoes expansion, so the (P) flag can operate on that.

> If I have the following in a script that reads input from stdin:
> 
> sed -n "s/$REGEX/\1\n/gp" <&0 | sed "/$REGEX/!d" > $TMP
> if [[ ! -s $TMP ]]; then
>   rm -f $TMP
>   exit 1
> fi
> ${EDITOR:-vi} $TMP
> 
> my $EDITOR (vim) will complain that 
> "Vim: Warning: Input is not from a terminal".  Is there a simple way to
> get around this?

Are you saying the early part is important, i.e. if you just run vi in
the script without the earlier bit it works?  That sounds unlikely,
although I haven't investigated in detail.  If that's not the case, you
probably need to do some direction to force vi to use /dev/tty.

I'm not sure why you have "<&0", that simply redirects standard input
from standard input.

-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK                          Tel: +44 (0)1223 692070



**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com
**********************************************************************



Messages sorted by: Reverse Date, Date, Thread, Author