* Re: delay argument interpretation
@ 1997-07-22 17:28 Zoltan T. Hidvegi
0 siblings, 0 replies; 7+ messages in thread
From: Zoltan T. Hidvegi @ 1997-07-22 17:28 UTC (permalink / raw)
To: hzoli; +Cc: schaefer, zsh-users
hzoli wrote:
> > The latter fails to set $show to empty when the pattern doesn't match
> > anything. I have nomatch set, so if there's a globbing failure in the
> > arg list, "show" never executes. I want to force "show" to start, and
> > *then* get the globbing failure.
>
> Alias show to noglob show.
Oh, I did not read the beginning of the mail. Sorry for my ignorance.
Zoltan
^ permalink raw reply [flat|nested] 7+ messages in thread
* delay argument interpretation
@ 1997-07-21 16:05 Paul Lew
1997-07-21 16:43 ` Andrew Main
1997-07-21 18:52 ` Bart Schaefer
0 siblings, 2 replies; 7+ messages in thread
From: Paul Lew @ 1997-07-21 16:05 UTC (permalink / raw)
To: zsh-users
I have a shell function 'ask' to aid the interactive command
execution, for example,
function ask {
echo -n "$*? [y/n]: "
read yon
if [[ "$yon" = "y" ]]; then
$@
echo "end of: $@"
fi
}
Then I can use commands similar to the one below to interactively
select the desired candidates:
for i in *.c; do
ask diff old/$i $i
done
will work like:
diff old/a.c a.c? [y/n]:
diff old/b.c b.c? [y/n]:
diff old/c.c c.c? [y/n]:
This all work out nice, however, the comment blocks in these files are
different and I would like to apply a filter (rmcmt in the example
below) to it so I will only see the source differences:
for i in *.c; do
ask diff =(rmcmt old/$i) =(rmcmt $i)
done
However the =(...) expanded info a temporary filename and the prompt
became:
diff /tmp/zshaaqqxa /tmp/zshaaqqxb? [y/n]:
diff /tmp/zshaaqqxa /tmp/zshaaqqxb? [y/n]:
diff /tmp/zshaaqqxa /tmp/zshaaqqxb? [y/n]:
What can I do to quote the arguments so it will not expand until
later in function ask? Any help will be appreciated...
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: delay argument interpretation
1997-07-21 16:05 Paul Lew
@ 1997-07-21 16:43 ` Andrew Main
1997-07-21 18:52 ` Bart Schaefer
1 sibling, 0 replies; 7+ messages in thread
From: Andrew Main @ 1997-07-21 16:43 UTC (permalink / raw)
To: Paul Lew; +Cc: zsh-users
function ask {
local yon
echo -n - >&2 "$1? [y/n]: "
read yon
[[ "$yon" == [yY]* ]] && eval "$1"
}
for i in *.c; do
ask 'diff =(rmcmt old/$i) =(rmcmt $i) # $i = '$i
done
There are other obvious variations.
-zefram
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: delay argument interpretation
1997-07-21 16:05 Paul Lew
1997-07-21 16:43 ` Andrew Main
@ 1997-07-21 18:52 ` Bart Schaefer
1997-07-22 8:23 ` Andrew Main
1 sibling, 1 reply; 7+ messages in thread
From: Bart Schaefer @ 1997-07-21 18:52 UTC (permalink / raw)
To: Paul Lew, zsh-users
On Jul 21, 12:05pm, Paul Lew wrote:
} Subject: delay argument interpretation
}
} This all work out nice, however, the comment blocks in these files are
} different and I would like to apply a filter (rmcmt in the example
} below) to it so I will only see the source differences:
}
} for i in *.c; do
} ask diff =(rmcmt old/$i) =(rmcmt $i)
} done
The obvious solution to this specific problem is to use "diff -I <re>" to
ignore lines matching the regular expression <re>.
The other solution that occurs to me is
function diffsrc() {
local x=$[$#-2]
diff $*[1,$x] =(rmcmt $*[$x+1]) =(rmcmt $*[$x+2])
}
for i in *.c; do ask diffsrc old/$i $i; done
} What can I do to quote the arguments so it will not expand until
} later in function ask?
Something like what Zefram suggested is the only way; really do quote them
yourself. In csh I'd use an alias with \!: expansions like this:
alias ask 'echo -n \!*:q"? [y/n] "; askify \!*'
(and then "askify" would be a script that does everything but the echo in
your "ask"). But zsh doesn't have such a mechanism for re-quoting the
command line at alias time, before any of it gets expanded. The closest
you can get is somthing like
alias ask='noglob ask'
which delays filename expansion but not command name substitution et. al.
I have this little function:
show () {
show=()
show=($~*)
print -rc $show
}
alias show='noglob show'
which allows me to do things like
show **/*.{orig,rej}
(examine what I see for a bit, then do something else like)
rm $show
(which avoids doing the recursive glob twice).
My only complaint about this is that completion for "noglob" gets invoked
if I happen to press TAB, rather than completion for "show". I think
that's a bug.
--
Bart Schaefer Brass Lantern Enterprises
http://www.well.com/user/barts http://www.brasslantern.com
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: delay argument interpretation
1997-07-21 18:52 ` Bart Schaefer
@ 1997-07-22 8:23 ` Andrew Main
1997-07-22 16:10 ` Bart Schaefer
0 siblings, 1 reply; 7+ messages in thread
From: Andrew Main @ 1997-07-22 8:23 UTC (permalink / raw)
To: Bart Schaefer; +Cc: lew, zsh-users
Bart Schaefer wrote:
> show () {
> show=()
> show=($~*)
> print -rc $show
> }
> alias show='noglob show'
Why? What's wrong with
function show {
show=("$@")
print -rc -- "$@"
}
-zefram
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: delay argument interpretation
1997-07-22 8:23 ` Andrew Main
@ 1997-07-22 16:10 ` Bart Schaefer
1997-07-22 17:25 ` Zoltan T. Hidvegi
0 siblings, 1 reply; 7+ messages in thread
From: Bart Schaefer @ 1997-07-22 16:10 UTC (permalink / raw)
To: zsh-users
On Jul 22, 9:23am, Andrew Main wrote:
> Subject: Re: delay argument interpretation
>
> Bart Schaefer wrote:
> > show () {
> > show=()
> > show=($~*)
> > print -rc $show
> > }
> > alias show='noglob show'
>
> Why? What's wrong with
>
> function show {
> show=("$@")
> print -rc -- "$@"
> }
The latter fails to set $show to empty when the pattern doesn't match
anything. I have nomatch set, so if there's a globbing failure in the
arg list, "show" never executes. I want to force "show" to start, and
*then* get the globbing failure.
--
Bart Schaefer Brass Lantern Enterprises
http://www.well.com/user/barts http://www.brasslantern.com
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: delay argument interpretation
1997-07-22 16:10 ` Bart Schaefer
@ 1997-07-22 17:25 ` Zoltan T. Hidvegi
0 siblings, 0 replies; 7+ messages in thread
From: Zoltan T. Hidvegi @ 1997-07-22 17:25 UTC (permalink / raw)
To: Bart Schaefer; +Cc: zsh-users
Bart Schaefer wrote:
> The latter fails to set $show to empty when the pattern doesn't match
> anything. I have nomatch set, so if there's a globbing failure in the
> arg list, "show" never executes. I want to force "show" to start, and
> *then* get the globbing failure.
Alias show to noglob show.
Zoli
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~1997-07-22 17:45 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-07-22 17:28 delay argument interpretation Zoltan T. Hidvegi
-- strict thread matches above, loose matches on Subject: below --
1997-07-21 16:05 Paul Lew
1997-07-21 16:43 ` Andrew Main
1997-07-21 18:52 ` Bart Schaefer
1997-07-22 8:23 ` Andrew Main
1997-07-22 16:10 ` Bart Schaefer
1997-07-22 17:25 ` Zoltan T. Hidvegi
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).