* Random sort qualifier
@ 2010-02-17 15:59 Mikael Magnusson
2010-02-17 16:02 ` Mikael Magnusson
0 siblings, 1 reply; 3+ messages in thread
From: Mikael Magnusson @ 2010-02-17 15:59 UTC (permalink / raw)
To: zsh workers
Possibly mostly useful for selecting a single random file via *(or[1])
I only looked at the involved functions for about 3 minutes so I can
make no guarantees more than "It seems to work."
diff --git a/Src/glob.c b/Src/glob.c
index 036f88c..ead6dfe 100644
--- a/Src/glob.c
+++ b/Src/glob.c
@@ -74,8 +74,9 @@ struct gmatch {
#define GS_NAME 1
#define GS_DEPTH 2
#define GS_EXEC 4
+#define GS_RANDOM 8
-#define GS_SHIFT_BASE 8
+#define GS_SHIFT_BASE 16
#define GS_SIZE (GS_SHIFT_BASE)
#define GS_ATIME (GS_SHIFT_BASE << 1)
@@ -995,6 +996,9 @@ gmatchcmp(Gmatch a, Gmatch b)
case GS__LINKS:
r = b->_links - a->_links;
break;
+ case GS_RANDOM:
+ r = 1 - 2*(rand() & 1);
+ break;
}
if (r)
return (int) ((s->tp & GS_DESC) ? -r : r);
@@ -1560,6 +1564,7 @@ zglob(LinkList list, LinkNode np, int nountok)
case 'c': t = GS_CTIME; break;
case 'd': t = GS_DEPTH; break;
case 'N': t = GS_NONE; break;
+ case 'r': t = GS_RANDOM; break;
case 'e':
case '+':
{
--
Mikael Magnusson
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Random sort qualifier
2010-02-17 15:59 Random sort qualifier Mikael Magnusson
@ 2010-02-17 16:02 ` Mikael Magnusson
2010-02-17 16:02 ` Mikael Magnusson
0 siblings, 1 reply; 3+ messages in thread
From: Mikael Magnusson @ 2010-02-17 16:02 UTC (permalink / raw)
To: zsh workers
On 17 February 2010 16:59, Mikael Magnusson <mikachu@gmail.com> wrote:
> Possibly mostly useful for selecting a single random file via *(or[1])
> I only looked at the involved functions for about 3 minutes so I can
> make no guarantees more than "It seems to work."
Of course, a minute after sending, I realized the same effect can be
achieved with *(oe:'REPLY=$RANDOM':[1]), not sure if it's worth having
a short form for it. (You can make a function for it and then say
*(+randsort[1]) too).
--
Mikael Magnusson
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Random sort qualifier
2010-02-17 16:02 ` Mikael Magnusson
@ 2010-02-17 16:02 ` Mikael Magnusson
0 siblings, 0 replies; 3+ messages in thread
From: Mikael Magnusson @ 2010-02-17 16:02 UTC (permalink / raw)
To: zsh workers
On 17 February 2010 17:02, Mikael Magnusson <mikachu@gmail.com> wrote:
> On 17 February 2010 16:59, Mikael Magnusson <mikachu@gmail.com> wrote:
>> Possibly mostly useful for selecting a single random file via *(or[1])
>> I only looked at the involved functions for about 3 minutes so I can
>> make no guarantees more than "It seems to work."
>
> Of course, a minute after sending, I realized the same effect can be
> achieved with *(oe:'REPLY=$RANDOM':[1]), not sure if it's worth having
> a short form for it. (You can make a function for it and then say
> *(+randsort[1]) too).
Grr, *(o+randsort[1]) of course :).
--
Mikael Magnusson
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2010-02-17 16:02 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-02-17 15:59 Random sort qualifier Mikael Magnusson
2010-02-17 16:02 ` Mikael Magnusson
2010-02-17 16:02 ` Mikael Magnusson
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).