Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue in mac command #40

Open
awebdeveloper opened this issue Aug 8, 2016 · 5 comments
Open

Issue in mac command #40

awebdeveloper opened this issue Aug 8, 2016 · 5 comments

Comments

@awebdeveloper
Copy link

Mac OS X

export PS1="\u@\h \W \[$txtcyn\]\$git_branch\[$txtred\]\$git_dirty\[$txtrst\]\$ "

Sq brackets are missing around $git_branch and $git_dirty

\[$txtcyn\]\[$git_branch\]\[$txtred\]\[$git_dirty\]\[$txtrst\]\$

@joeytwiddle
Copy link

Square brackets are needed for non-printing characters (the colour codes). They will prevent the terminal from counting those characters when calculating the number of columns.

For characters which are displayed, the terminal needs to count them, so I don't think they should be in square brackets.

Was there any bug you experienced related to this?

@Veloxious
Copy link

Super late to the thread. I was also having an issue where the variable $git_branch was being displayed as text (e.g. $git_branch) instead of the actual branch name.

awebdeveloper's solve made it work.

@lethosor
Copy link
Contributor

Can you post the prompt(s) that worked and didn't work for you? Putting \[ and \] around printable text like $git_branch is simply not correct.

@Veloxious
Copy link

Sure,

My current working ps1 export
export PS1='\e[0;32m\t\e[m \e[0;34m\u\e[m \w \e[0;35m\[$git_branch\]\e[m\nλ: '

and the previous export (that was not working but now is, likely user error)
export PS1='\e[0;32m\t\e[m \e[0;34m\u\e[m \w \e[0;35m$git_branch\e[m\nλ: '

as I said, now both of these exports work correctly. when I set this up I must have forgotten to source or restart my session.

@joeytwiddle
Copy link

joeytwiddle commented Dec 23, 2018

It looks like the confusion has arisen from using ' instead of " for the prompt string.

If you use " then \$ is needed.
If you use ' then $ is needed.

But in either case, square brackets are not desirable around visible text.

\[$git_branch\] should just be $git_branch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants