Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Feature request: two level sorting
- X-seq: zsh-users 21660
- From: Sebastian Gniazdowski <sgniazdowski@xxxxxxxxx>
- To: Zsh Users <zsh-users@xxxxxxx>
- Subject: Feature request: two level sorting
- Date: Wed, 15 Jun 2016 07:13:59 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:from:date:message-id:subject:to; bh=ejnOmIajb5cdt/A+vY5dGl7vBuhe0S2yFKW53/BmPMU=; b=uG+b8aMPKmdCaAMsZCkhfMM+lDpdzGn4A6v7SInxDXHQ2TZSDY6dENCwuQv44mKPgi x9jvVV+h22dydGAPdyrXBwDtAiUA0rsV39C6wlXaSDYxGxY48yYIsT8bwV5EFBxHsY2K BiaMEGONvB9YSaqrmRQzShDPsNDRIf0+rR5WQPhIb3NJsYCfz1YC8pMytv1/Yb0o0txn SfGNL+oxOwrAqAdTmdS32bXLjcmeRZ+URYcHpdEE6kQkN2nU4IemAXGDbAU6Xay6DNc1 qTu+DRaMx00nR5oK9p4NtU3hxnf6wWOw2eqfvEyukyrRc/D0fDSTbnWtUxxCe1dEmsRi 9H7w==
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author