zsh-users
 help / color / mirror / code / Atom feed
* Feature request: two level sorting
@ 2016-06-15  5:13 Sebastian Gniazdowski
  2016-06-15  5:21 ` Sebastian Gniazdowski
  2016-06-15 17:12 ` Bart Schaefer
  0 siblings, 2 replies; 16+ messages in thread
From: Sebastian Gniazdowski @ 2016-06-15  5:13 UTC (permalink / raw)
  To: Zsh Users

Hello
Suppose you have set of file names:

files=( "aaa-A" "aab-B" "aac-A" "aad-C" )

when sorted normally, it will yield:

# print -rl -- ${(o)files[@]}
aaa-A
aab-B
aac-A
aad-C

when sorted with grouping on A, this will be:

aaa-A
aac-A
aab-B
aad-C

**The thing is** that it is easy to provide group names in separate array:

# groups=( "${files[@]//(#b)*([A-Z])/$match[1]}" )
# print -rl -- "${groups[@]}"
A
B
A
C

With that in place, one can sort with the grouping in following way:

    files=( "${(o)files[@]}" )
    group_letters=( A B C )
    integer a i grsize="${#group_letters}" size="${#files}"
    out=( )
    for (( a=1; a<=grsize; a++ )); do
        selected_group="${group_letters[a]}"
        for (( i=1; i<=size; i++ )); do
            [ "$selected_group" != "${groups[i]}" ] && continue
            out+=( "${files[i]}" )
        done
    done
    print -rl "${out[@]}"

So this is somewhat an amount of code. The group-sort flag could take
group names of sorted data in additional parameter, e.g.:
"${(ox:group_letters:)files}"

Best regards,
Sebastian Gniazdowski


^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2016-07-02 17:18 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-15  5:13 Feature request: two level sorting Sebastian Gniazdowski
2016-06-15  5:21 ` Sebastian Gniazdowski
2016-06-15  6:10   ` Sebastian Gniazdowski
2016-06-15 17:12 ` Bart Schaefer
2016-06-15 18:25   ` Mikael Magnusson
2016-06-15 22:38     ` Bart Schaefer
2016-06-15 23:02       ` Mikael Magnusson
2016-06-16 15:43         ` Bart Schaefer
2016-07-01  7:16         ` Sebastian Gniazdowski
2016-07-01 16:43           ` Bart Schaefer
2016-07-02  4:09             ` Sebastian Gniazdowski
2016-07-02 17:18               ` Bart Schaefer
2016-06-16  4:53   ` Sebastian Gniazdowski
2016-06-16  7:21     ` Bart Schaefer
2016-06-18 10:56       ` Sebastian Gniazdowski
2016-06-19 17:42         ` Bart Schaefer

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).