* ideas
@ 1998-03-18 8:03 Quinn Dunkan
1998-03-18 14:57 ` ideas Christopher Craig
1998-03-18 17:51 ` ideas Bart Schaefer
0 siblings, 2 replies; 4+ messages in thread
From: Quinn Dunkan @ 1998-03-18 8:03 UTC (permalink / raw)
To: zsh-users
Here are a few ideas for new zsh features. It may be that it is already
possible to do these things with existing features, if so I'd love to know
how.
${...#...} and ${...%...} chop things off the begginning or ends of variables,
and I've wondered why there isn't something like ${i:s/foo/bar} to replace foo
in $i with bar. With ${(S)...%...} one can chop things out of the center of a
variable, but what if you want to replace it with soething else? Actually, it
would be even better if you could put in a regexp. Regexps in the [[ ]]
construct would be nice too---"if echo $blah | grep -q; then..." is kind of
clumsy. I've written some really ugly perl scripts that would have been much
nicer in shell, but weren't because no shell I know of has very powerful string
handling.
In HPUX, you can chase symlinks by sticking a / on the end of them, even if
they're not directories. Example:
% touch a
% ln -s a b
% ls -F
a
b@
% rm b/
% ls
a
%
Other OSs don't do this, and even in zsh, something like:
% ls -l =latex
lrwxrwxrwx 1 root tex 7 Aug 14 1997 /usr/local/lib/texmf/bin/latex -> latex2e
% ls -l =latex/
lrwxrwxrwx 1 root tex 6 Aug 14 1997 /usr/local/lib/texmf/bin/latex2e -> virtex
% ls -l =latex//
-rwxr-xr-x 1 root tex 198196 Dec 7 1996 /usr/local/lib/texmf/bin/virtex
won't work because zsh doesn't know about it, and you can't resolve them with
tab. Even though it's an operating system feature, I see know reason why the
shell couldn't do it too.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: ideas
1998-03-18 8:03 ideas Quinn Dunkan
@ 1998-03-18 14:57 ` Christopher Craig
1998-03-18 17:14 ` ideas Bernd Eggink
1998-03-18 17:51 ` ideas Bart Schaefer
1 sibling, 1 reply; 4+ messages in thread
From: Christopher Craig @ 1998-03-18 14:57 UTC (permalink / raw)
To: Quinn Dunkan; +Cc: zsh-users
Included From: Quinn Dunkan <quinn@envy.ugcs.caltech.edu>:
> and I've wondered why there isn't something like ${i:s/foo/bar} to
> replace foo in $i with bar.
You could just use $i(:s/foo/bar).
--
Christopher A. Craig <ccraig@cc.gatech.edu>
"Efficiency is intelligent laziness" Arnold H. Glasow
PGP Key Verification: EE B1 F3 A0 3F BC 3C C7 81 61 F1 91 6E 99 13 65
http://www.cc.gatech.edu/people/home/ccraig
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: ideas
1998-03-18 14:57 ` ideas Christopher Craig
@ 1998-03-18 17:14 ` Bernd Eggink
0 siblings, 0 replies; 4+ messages in thread
From: Bernd Eggink @ 1998-03-18 17:14 UTC (permalink / raw)
To: Christopher Craig; +Cc: Quinn Dunkan, zsh-users
Christopher Craig wrote:
>
> Included From: Quinn Dunkan <quinn@envy.ugcs.caltech.edu>:
>
> > and I've wondered why there isn't something like ${i:s/foo/bar} to
> > replace foo in $i with bar.
>
> You could just use $i(:s/foo/bar).
Great! I, too, was wondering why there isn't such a thing. Now I wonder
if this feature is considered top secret. I can't find anything about it
in the docu.
And, BTW, at least in zsh-3.1.2-zefram3, this doesn't work correctly.
print abcdefg(:s/b/XY)
aXYecdefg
where the e following Y has two dots on it. But this works:
print abcdefg(:s/b/XY/)
aXYcdefg
- Bernd
--
Bernd Eggink
Regionales Rechenzentrum der Universitaet Hamburg
eggink@rrz.uni-hamburg.de
http://www.rrz.uni-hamburg.de/eggink/BEggink.html
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: ideas
1998-03-18 8:03 ideas Quinn Dunkan
1998-03-18 14:57 ` ideas Christopher Craig
@ 1998-03-18 17:51 ` Bart Schaefer
1 sibling, 0 replies; 4+ messages in thread
From: Bart Schaefer @ 1998-03-18 17:51 UTC (permalink / raw)
To: zsh-users
On Mar 18, 12:03am, Quinn Dunkan wrote:
} Subject: ideas
}
} ${...#...} and ${...%...} chop things off the begginning or ends
} of variables, and I've wondered why there isn't something like
} ${i:s/foo/bar} to replace foo in $i with bar. With ${(S)...%...}
} one can chop things out of the center of a variable, but what if
} you want to replace it with soething else?
In addition to ${var}(:s/foo/bar/) [which BTW in 3.0.5 requires the
trailing / to work correctly, a bug] there's always
${var%foo*}bar${var#*foo}
Or even
r=(${(BE)=var%foo*})
l=(${(BE)=var#*foo})
${var[$l[1],$r[1]-1]}bar${$var[$l[2],$r[2]-1]}
In which case the removed portion is
${var[$r[1],$l[2]-1]}
} Actually, it would be even better if you could put in a regexp.
How often is a glob pattern not sufficient? With extendedglob, you
can write almost any regexp as a glob. The big thing you lose is the
ability to substitute the matches for sub-patterns of the regexp into
the replacement.
--
Bart Schaefer Brass Lantern Enterprises
http://www.well.com/user/barts http://www.brasslantern.com
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~1998-03-18 18:07 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-03-18 8:03 ideas Quinn Dunkan
1998-03-18 14:57 ` ideas Christopher Craig
1998-03-18 17:14 ` ideas Bernd Eggink
1998-03-18 17:51 ` ideas Bart Schaefer
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).