zsh-users
 help / color / mirror / code / Atom feed
From: Mikael Magnusson <mikachu@gmail.com>
To: Bart Schaefer <schaefer@brasslantern.com>
Cc: Zsh Users <zsh-users@zsh.org>
Subject: Re: Feature request: two level sorting
Date: Thu, 16 Jun 2016 01:02:51 +0200	[thread overview]
Message-ID: <CAHYJk3SOca2W212_KZLskjD0iUOy7gdxUx81H07B07HGHNN=CQ@mail.gmail.com> (raw)
In-Reply-To: <160615153817.ZM22021@torch.brasslantern.com>

On Thu, Jun 16, 2016 at 12:38 AM, Bart Schaefer
<schaefer@brasslantern.com> wrote:
> On Jun 15,  8:25pm, Mikael Magnusson wrote:
> }
> } Can we do what the oe:: flag does for globbing? Ie, pass each element
> } to a custom code snippet that transforms it arbitrarily, and sort on
> } the output.
>
> We considered that a while back, but the problem is that if you allow
> arbitrary shell code to be called from within the sort algorithm there
> are way too many opportunities for madness.
>
> With globbing, there's one well-defined place -- the read of the name
> from the directory structure -- where the callback can be applied to
> a single data element.  With a sort, the callback may be invoked many
> times for pairs of data, sometimes even more than once for the same
> pair depending on the algorithm, and unlike e.g. perl that has object
> pointers and reference-count garbage collection and lexical scopiing
> and a whole other panoply of protections against the user shooting
> himself, in zshell code all sorts of havoc could be wrought.  (Yeah,
> you can probably create the same havoc in perl if you work at it, but
> it's a lot more difficult.)

Ah, yeah I suppose that makes sense, we would have to add a bunch of
extra internal state to track the "sort-name" for each member during
expansion, which is very specific, if we wanted to avoid the multiple
calls.

> Falling back to something lesser/safer amounts to inventing a whole
> new mini-language.  It's just not worth it to internalize in the shell
> something that (a) other languages do better and (b) was intended by
> the original architecture to be done in an outside process anyway.

Well, this old trick always works if you don't mind depending on /
being readable, but that's probably a safe assumption usually.

% myarray=("aaa-A" "aab-B" "aac-A" "aad-C")
% echo /(e:'reply=($myarray)':oe:'REPLY=${REPLY#*-}':)
aac-A aaa-A aab-B aad-C

-- 
Mikael Magnusson


  reply	other threads:[~2016-06-15 23:02 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-15  5:13 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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAHYJk3SOca2W212_KZLskjD0iUOy7gdxUx81H07B07HGHNN=CQ@mail.gmail.com' \
    --to=mikachu@gmail.com \
    --cc=schaefer@brasslantern.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).