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

Re: Convert control characters to bindkey/quoted-insert -style escape sequences



On Wed, Jan 24, 2024 at 2:36 PM Marlon Richert <marlon.richert@xxxxxxxxx> wrote:
>
> I know I can convert control characters to $'...' -style escape sequences using ${(qqqq)...} or ${(q+)...} expansion.
>
> However, how can I convert control characters to bindkey/quoted-insert -style escape sequences?
>
> For example, I want to convert a newline character to ^M and not $'\n'
>
> Basically, I want the inverse of a ${(g:c:)...} expansion.

That thing with psvar that you described in another thread is
${(V)name}. It'll give you ^M (rather than \r) as you seem to want.
You are still going to get \n instead of ^J and \t instead of ^I. It's
pretty good in practice for what it is meant to do: make a string
presentable to humans. It's not particularly consistent with the
choice of C-escapes vs carets though.

I don't know if there is a way to encode special characters
exclusively through caret notation. This encoding is fairly simple, so
you could also do it manually if you need to.

Roman.




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