ZSH prompt issue : commands shifted to the right on one hundred space characters when doing completions, i.e using TAB key

To be candid, I think your making this prompt overly complex and attempting to introduce additional, complex "layers" to what's supposed to be a simple prompt is having unforeseen and unpredictable issues.

In my previous answer to your related question, which what you based your slash_color function on, I cautioned against this from a usability standpoint. In the comments, I mentioned that I wasn't amenable to putting a function within a prompt for security reasons.

Ok...disclaimers are out of the way.


My first observation is that you have a newline character being generated by awk.

slash_color code

So, in your prompt, you're telling it to output a new line in something that's supposed to be contained to a single line. I don't now how PROMPT handles things within ZSH, but I doubt it handles new line chars very well.

Secondly, you seem to be mixing up all the different things that ZSH, awk, and functions in general have to deal with. I'm still a bit foggy as to the actual logic here, but it seems like you're trying to push "normal" escape codes through two layers of functions within ZSH by using their color conventions and ZSH's loadable modules.

Could anyone take a look please at the 2 links that I gave above, it could contain the solution in my case?

Why? What in those links lead you to believe that? The first link is about variable expansion within the prompt. The second show you how to colorize your prompt using both escape sequences and the preferred braces method in ZSH.

I believe the issue is the over-complexity.

You're shoehorning a function that not only has the ANSI escape codes, which are supported, but calling another function that creates a pipe, which means it creates a sub shell to call yet another function! (This is what I was referring to re: layers and complexity).

This is why I suggested using precmd(). Not only can you nest functions, but you can call multiple functions and then generate your prompt. I advise you to explore that more and not fixate on PROMPT being the sole method to skin this cat.

My other piece of advice is to articulate what you'd ultimately like to accomplish and post that as a new question because there's probably a solution you're not aware of. IMO, this sounds like an XY Problem