* globbing and quoting in a function
@ 2005-07-19 14:27 Stefan Reichör
2005-07-19 14:59 ` Doug Kearns
0 siblings, 1 reply; 8+ messages in thread
From: Stefan Reichör @ 2005-07-19 14:27 UTC (permalink / raw)
To: zsh-users
Hi!
I use the following alias to show the last 30 files changed:
alias lsnew='ls -tr -dl *(om[1,30])'
Now I want to convert it to a function to specify the '*' as
parameter:
I tried the following, but the $1 is not combined with the glob
modifier.
function lsnew () {
ls -tr -dl $1(om[1,30])
}
So is there a way to make 'lsnew a*' work?
Stefan.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: globbing and quoting in a function
2005-07-19 14:27 globbing and quoting in a function Stefan Reichör
@ 2005-07-19 14:59 ` Doug Kearns
2005-07-19 15:29 ` Wayne Davison
2005-07-19 15:35 ` Stefan Reichör
0 siblings, 2 replies; 8+ messages in thread
From: Doug Kearns @ 2005-07-19 14:59 UTC (permalink / raw)
To: zsh-users
On Tue, Jul 19, 2005 at 04:27:32PM +0200, Stefan Reichör wrote:
> Hi!
>
> I use the following alias to show the last 30 files changed:
>
> alias lsnew='ls -tr -dl *(om[1,30])'
>
>
> Now I want to convert it to a function to specify the '*' as
> parameter:
>
> I tried the following, but the $1 is not combined with the glob
> modifier.
>
> function lsnew () {
> ls -tr -dl $1(om[1,30])
ls -tr -dl $~1(om[1,30])
> }
>
>
> So is there a way to make 'lsnew a*' work?
You'll need to quote the * as well. For example,
lsnew a\*
Regards,
Doug
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: globbing and quoting in a function
2005-07-19 14:59 ` Doug Kearns
@ 2005-07-19 15:29 ` Wayne Davison
2005-07-20 3:54 ` Bart Schaefer
2005-07-19 15:35 ` Stefan Reichör
1 sibling, 1 reply; 8+ messages in thread
From: Wayne Davison @ 2005-07-19 15:29 UTC (permalink / raw)
To: zsh-users
On Wed, Jul 20, 2005 at 12:59:55AM +1000, Doug Kearns wrote:
> You'll need to quote the * as well.
Or use "noglob" as a prefix, which can be done using an alias:
alias lsnew='noglob lsnew'
Then you can use "lsnew foo*" without quoting any wildcards.
(I vaguely recall that having an alias call a function of the same name
might cause a problem in some older zsh versions, but it works fine in
4.2.5.)
..wayne..
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: globbing and quoting in a function
2005-07-19 14:59 ` Doug Kearns
2005-07-19 15:29 ` Wayne Davison
@ 2005-07-19 15:35 ` Stefan Reichör
1 sibling, 0 replies; 8+ messages in thread
From: Stefan Reichör @ 2005-07-19 15:35 UTC (permalink / raw)
To: zsh-users; +Cc: zsh-workers
Doug Kearns <dougkearns@gmail.com> writes:
> On Tue, Jul 19, 2005 at 04:27:32PM +0200, Stefan Reichör wrote:
>> Hi!
>>
>> I use the following alias to show the last 30 files changed:
>>
>> alias lsnew='ls -tr -dl *(om[1,30])'
>>
>>
>> Now I want to convert it to a function to specify the '*' as
>> parameter:
>>
>> I tried the following, but the $1 is not combined with the glob
>> modifier.
>>
>> function lsnew () {
>> ls -tr -dl $1(om[1,30])
>
> ls -tr -dl $~1(om[1,30])
>
>> }
>>
>>
>> So is there a way to make 'lsnew a*' work?
>
> You'll need to quote the * as well. For example,
>
> lsnew a\*
That does not work as expected:
lsnew:1: no matches found: a*(om[1,30])
I would like to see all files, starting with a.
The quoted \* seems to match the *.
Stefan.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: globbing and quoting in a function
2005-07-19 15:29 ` Wayne Davison
@ 2005-07-20 3:54 ` Bart Schaefer
2005-07-20 5:24 ` Stefan Reichör
0 siblings, 1 reply; 8+ messages in thread
From: Bart Schaefer @ 2005-07-20 3:54 UTC (permalink / raw)
To: zsh-users
On Jul 19, 8:29am, Wayne Davison wrote:
} Subject: Re: globbing and quoting in a function
}
} alias lsnew='noglob lsnew'
}
} (I vaguely recall that having an alias call a function of the same
} name might cause a problem in some older zsh versions, but it works
} fine in 4.2.5.)
The "problem" is still there. See the last few paragraphs of FAQ
question 2.3.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: globbing and quoting in a function
2005-07-20 3:54 ` Bart Schaefer
@ 2005-07-20 5:24 ` Stefan Reichör
2005-07-20 7:48 ` Bart Schaefer
0 siblings, 1 reply; 8+ messages in thread
From: Stefan Reichör @ 2005-07-20 5:24 UTC (permalink / raw)
To: zsh-users; +Cc: zsh-workers
Bart Schaefer <schaefer@brasslantern.com> writes:
> On Jul 19, 8:29am, Wayne Davison wrote:
> } Subject: Re: globbing and quoting in a function
> }
> } alias lsnew='noglob lsnew'
> }
> } (I vaguely recall that having an alias call a function of the same
> } name might cause a problem in some older zsh versions, but it works
> } fine in 4.2.5.)
>
> The "problem" is still there. See the last few paragraphs of FAQ
> question 2.3.
So my question is still open:
Consider the following command:
ls -tr -dl *(om[1,30])
Now I would like to create an alias/or a function/or whatever to make
the * variable.
I'd like to call:
lsnew *
lsnew a*
Is there an easy way to do it in zsh?
The only idea that I have at the moment is to create a script on the
fly and execute it.
Other ideas?
Stefan.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: globbing and quoting in a function
2005-07-20 5:24 ` Stefan Reichör
@ 2005-07-20 7:48 ` Bart Schaefer
2005-07-20 8:29 ` Stefan Reichör
0 siblings, 1 reply; 8+ messages in thread
From: Bart Schaefer @ 2005-07-20 7:48 UTC (permalink / raw)
To: zsh-users
This business with gmane double-posting to both zsh-users and zsh-workers
is getting annoying. As gmane is apparently not clever enough to get this
right by themselves, would you gmane users please be polite and trim off
one of the two newsgroups when posting? (I don't know what names gmane
gives to their groups that are gatewayed to the zsh lists.)
On Jul 20, 7:24am, Stefan Reichör wrote:
}
} I'd like to call:
} lsnew *
} lsnew a*
}
} Is there an easy way to do it in zsh?
Yes. It's been answered in the previous postings.
function lsnew { ls -tr -dl $~1(om[1,30]) }
alias lsnew='noglob lsnew'
Once the alias has been defined, you must not attempt to re-define the
lsnew function unless you do so using the "function" keyword as above.
The existence of the alias causes the
lsnew() { ... }
syntax to do something different from what you would expect.
A drawback to the above is that you cannot do
lsnew *(.)
because that expands to
ls -tr -dl *(.)(om[1,30])
and two sets of glob qualifiers don't mix.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: globbing and quoting in a function
2005-07-20 7:48 ` Bart Schaefer
@ 2005-07-20 8:29 ` Stefan Reichör
0 siblings, 0 replies; 8+ messages in thread
From: Stefan Reichör @ 2005-07-20 8:29 UTC (permalink / raw)
To: zsh-users
Bart Schaefer <schaefer@brasslantern.com> writes:
> On Jul 20, 7:24am, Stefan Reichör wrote:
> }
> } I'd like to call:
> } lsnew *
> } lsnew a*
> }
> } Is there an easy way to do it in zsh?
>
> Yes. It's been answered in the previous postings.
>
> function lsnew { ls -tr -dl $~1(om[1,30]) }
> alias lsnew='noglob lsnew'
Thanks for summarizing it. I overlooked the ~ in Doug's message.
I use it now the following way to allow calling without a parameter also:
function lsnew () {
if [[ $1 = "" ]]; then
lsnew_glob="*"
else
lsnew_glob=$1
fi
ls -tr -dl $~lsnew_glob(om[1,30])
}
alias lsnew='noglob lsnew'
Stefan.
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2005-07-20 8:31 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-07-19 14:27 globbing and quoting in a function Stefan Reichör
2005-07-19 14:59 ` Doug Kearns
2005-07-19 15:29 ` Wayne Davison
2005-07-20 3:54 ` Bart Schaefer
2005-07-20 5:24 ` Stefan Reichör
2005-07-20 7:48 ` Bart Schaefer
2005-07-20 8:29 ` Stefan Reichör
2005-07-19 15:35 ` Stefan Reichör
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).