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

Re: protection racket

On 05/02/18 01:20 PM, Ray Andrews wrote:

    _execute apt-cache show  \"$1\" \| egrep --color=always \"^\|$1\" \| sed -r \'/^Package: / s/\\x1b\\[\([0-9]\{1,2\}(\;[0-9]\{1,2\})?\)\?[m\|K]//g\' \| sed -r \'s/(Package: .*)/\\x1b\[33\;1m\\1\\x1b\[0m/\'

This solves all issues and is both robust (I think) and understandable:

    ... sed -re \''/^Package: / s/\x1b\[([0-9]{1,2}(;[0-9]{1,2})?)?[m\|K]//g'\' ...
^^ ^^

Outer protected single quotes go forward to sed as sed demands, but inner single quotes guarantee all characters between them are protected, one and all, but are removed as the string goes forward once they've done their job of protecting the string.  I'd still like to know why the individual characters needed protection  above, but never mind, it might be beyond human understanding given how loaded sed strings are with potentially special characters, special both to sed and/or to zsh, so maybe better not to even think about it when an easy solution is at hand.

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