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

Re: Feature request (@M):# with context matches



On 30 January 2016 at 15:38, Christian Heinrich
<christian@xxxxxxxxxxxxxxx> wrote:
> Hi Sebastian,
>
> I'm not sure what you want to do, but I my guts tells me that you want
> to re-invent the wheel as you stated that you want to replace several
> tools with ZSH. If you can achieve your goal by calling a GNU tool, you
> should do that. These are mature tools and there is nothing wrong about
> using them. (And it's certainly a benefit that you don't have to
> maintain them.)
>
> Calling "grep" is also more understandable by everyone than the pattern
> you gave in your first email.

I'll try to contradict the "more understandable" with an example –
antigen, a probably very well written BSG code. Take this function for
example:

https://github.com/zsh-users/antigen/blob/master/antigen.zsh#L100-L112

antigen-bundles () {
    # Bulk add many bundles at one go. Empty lines and lines starting with a `#`
    # are ignored. Everything else is given to `antigen-bundle` as is, no
    # quoting rules applied.

    local line

    grep '^[[:space:]]*[^[:space:]#]' | while read line; do
        # Using `eval` so that we can use the shell-style quoting in each line
        # piped to `antigen-bundles`.
        eval "antigen-bundle $line"
    done
}

For me it's hard to understand this function. Grep, forks, pipes,
evals. My point is that this is what "$( )" leads to in general.
That's what ABSG advises to do, and such code is spread everywhere,
across companies, open source projects. Other example:

https://github.com/zsh-users/antigen/blob/master/antigen.zsh#L347-L355

    # Find directores in ADOTDIR/repos, that are not in the bundles record.
    local unused_clones="$(comm -13 \
        <(-antigen-echo-record |
            awk '$4 == "true" {print $1}' |
            while read line; do
                -antigen-get-clone-dir "$line"
            done |
            sort -u) \
        <(\ls -d "$ADOTDIR/repos/"* | sort -u))"

This is one candidate to most outstanding BSG snippet in the project.

On the other hand, such programming is maybe something distinct from
typical imperative programming. With my "GNU -> zsh" document, I would
maybe advocate how to do normal programming in Zsh. But I believe I
wouldn't, Zsh has it's own unique traits, own ways of compressing much
into little of code, without use of Awk.

Best regards,
Sebastian Gniazdowski



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