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

Random sort qualifier



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



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