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

Re: Sorting file names randomly

    Hi Bart :)

 * Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> dixit:
> On Jul 23,  9:42pm, DervishD wrote:
> }
> }     shuffle dir1/* dir2/* ...
> There's no reason to noglob and alias this.  The space required to
> expand the glob on the command line is no worse than what you're
> doing inside the function anyway, and there aren't argument-size
> limits on calls to shell functions, only on external commands.

    How about this?:

function shuffle () {

    emulate -L zsh 
    setopt nullglob globdots rcexpandparam
    RANDOM=`date +%s`
    [[ $# -eq 0 ]] && set '*'

    reply=($reply(e:'REPLY="${(l.5..0.)RANDOM} $REPLY"':))
    reply=(${reply/#????? /})

    print -l $reply

    return 0

    It does the globbing outside, and shuffles correctly. Any way of
making the 'reply' assignments shorter? Should I go definitely for a
'for' loop and an associative array?

    Thanks a lot :)

    Raúl Núñez de Arenas Coronado

Linux Registered User 88736 | http://www.dervishd.net
http://www.pleyades.net & http://www.gotesdelluna.net
It's my PC and I'll cry if I want to...

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