bash-prompt-generator icon indicating copy to clipboard operation
bash-prompt-generator copied to clipboard

The Tool Is Generating A PS1 String With Unexpected Leading Characters

Open jmartin111 opened this issue 3 years ago • 9 comments

This prompt:

  • PS1='[\e[0;1;38;5;212m]$(git branch 2>/dev/null | grep '"'"'^*'"'"' | colrm 1 2) [\e[0;1;38;5;46m]\u[\e[0;38;5;227m]@[\e[0;1;38;5;46m]\h[\e[0m]:[\e[0;1;38;5;45m]/[\e[0;1;38;5;45m]\W[\e[0;1;38;5;226m]# [\e[0m]'

is resulting in the following prompt when set in my .bashrc file. Screenshot of the generator page below

  • ]main jeff@machine:/var$

Where are these two leading characters coming from?

  • ]

Note: view this in plaintext mode so the markdown editor doesn't render them differently. This is also important because the renderer is removing non-escaped backslashes

Bash Prompt Generator-2022-09-12

jmartin111 avatar Sep 13 '22 00:09 jmartin111

I cannot reproduce this issue. The prompt string works perfectly fine for me: screenshot_000

Can you post the output from git branch 2>/dev/null?

Scriptim avatar Sep 13 '22 07:09 Scriptim

You are seeing the issue but the characters aren’t rendering.

Notice how your prompt is offset two spaces to the right?

I see the same thing on my MacBook bash terminal. The original issue was seen on WSL and somehow that environment is rendering the special characters as opposed to just spaces.

On Sep 13, 2022, at 00:54, Tim @.***> wrote:

I cannot reproduce this issue. The prompt string works perfectly fine for me: https://user-images.githubusercontent.com/13003924/189843301-030baf73-0a99-4b6f-94f1-218fdf2ab7c5.png Can you post the output from git branch 2>/dev/null?

— Reply to this email directly, view it on GitHub https://github.com/Scriptim/bash-prompt-generator/issues/13#issuecomment-1245036441, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB72CEWC66H2WOZSM43F7JLV6AXL7ANCNFSM6AAAAAAQK6QDWU. You are receiving this because you authored the thread.

jmartin111 avatar Sep 13 '22 16:09 jmartin111

If I remove the GIt branch portion, everything looks fine. Please see the attached screenshot.

On Sep 13, 2022, at 00:54, Tim @.***> wrote:

I cannot reproduce this issue. The prompt string works perfectly fine for me: https://user-images.githubusercontent.com/13003924/189843301-030baf73-0a99-4b6f-94f1-218fdf2ab7c5.png Can you post the output from git branch 2>/dev/null?

— Reply to this email directly, view it on GitHub https://github.com/Scriptim/bash-prompt-generator/issues/13#issuecomment-1245036441, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB72CEWC66H2WOZSM43F7JLV6AXL7ANCNFSM6AAAAAAQK6QDWU. You are receiving this because you authored the thread.

jmartin111 avatar Sep 13 '22 16:09 jmartin111

Notice how your prompt is offset two spaces to the right?

The prompt ist offset by one space. This is the space character element that comes between the Git branch and the username. It appears to be an offset here only because I was in a directory that does not contain a git repo. In a git repository, the prompt looks like this:

screenshot

Scriptim avatar Sep 14 '22 08:09 Scriptim

Can you show me the output when you manually run git branch | grep '^*' | cat -A in the according directory?

Scriptim avatar Sep 14 '22 08:09 Scriptim

@.***:~/projects/tmp$ git status On branch test-branch

No commits yet

nothing to commit (create/copy files and use "git add" to track) @.:~/projects/tmp$ git branch | grep '^' | cat -A cat: illegal option -- A usage: cat [-belnstuv] [file ...] @.*:~/projects/tmp$

On Sep 14, 2022, at 01:33, Tim @.***> wrote:

git branch | grep '^*' | cat -A

jmartin111 avatar Sep 14 '22 17:09 jmartin111

That's odd. What platform are you on exactly (operating system version, bash version, terminal software)?

Which output does git branch | grep '^*' produce (without the cat pipe which apparently has no -A option in your system's implementation)?

Scriptim avatar Sep 14 '22 20:09 Scriptim

Thats he odd thing. ‘Git branch’ returns nothing at all even by itself. I am looking in to that. You can probably close this ticket. I have found an alternate PS1 builder that does what I need.

Thanks for all your time and help; I really apprecitate it.

On Sep 14, 2022, at 13:31, Tim @.***> wrote:

git branch | grep '^*'

jmartin111 avatar Sep 14 '22 22:09 jmartin111

I have found an alternate PS1 builder that does what I need.

Just out of interest, could you show me the working PS1 string from the other tool so I can see what that one does differently?

Scriptim avatar Sep 15 '22 08:09 Scriptim