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

Any modifications required for Mac OS? #4

Closed
grigoryvp opened this issue Aug 26, 2015 · 14 comments
Closed

Any modifications required for Mac OS? #4

grigoryvp opened this issue Aug 26, 2015 · 14 comments

Comments

@grigoryvp
Copy link
Contributor

Hello and thanks for amazing work!

All works fine except line length: since you don't escape color codes via additional pair of "[" and "]", macos thinks that prompt has much greater length than actually is and wraps text being entered early.

What else do I need to add into my ~/.bashrc to fix this issue? Maybe some flag or general setting is required?

illustration

@michaeldfallen
Copy link
Owner

Ah, interesting. I don't fully color codes so I've only done what I can to get it working. Can you suggest fixes that would solve this? The docs online are very dense so hard to grasp.

@michaeldfallen
Copy link
Owner

I've tried adding the \[ you mentioned around the color codes so for example:

local red_unstaged_prefix="\[\033[1;31m\]"

That gives:

screen shot 2015-08-26 at 12 26 40

seems the \[ is getting escaped

@grigoryvp
Copy link
Contributor Author

Yep, seems some escaping problems. Need to dig it deeper!

@michaeldfallen
Copy link
Owner

I wouldn't be surprised if my use of printf is messing things around.

@michaeldfallen
Copy link
Owner

Thanks for the pull request btw

@michaeldfallen
Copy link
Owner

Using: printf '%q' $(./../git-radar/git-radar --bash) I get:

\\[\E[1;30m\\]git:(\\[\E[0m\\]\\[\E[0;37m\\]master\\[\E[0m\\]\\[\E[1;30m\\])\\[\E[0m\\]

So the \ is getting escaped at some point

@grigoryvp
Copy link
Contributor Author

I have tested on my machine, escaping works fine. How did you received this screenshot?

screenshot

Please note, that "[" and "]" is a PS1-specific magic, it will not work if just printed from terminal

Can you please check #7 on your machine?

@michaeldfallen
Copy link
Owner

Figured it out, I had my .bashrc set to:

export PS1='\W$(~/Projects/personal/git-radar/git-radar --bash) '

The correct way is:

export PS1="\W$(~/Projects/personal/git-radar/git-radar --bash) "

I.E. the ' should be ".

@grigoryvp
Copy link
Contributor Author

So if you use double quotes in your .bashrc file my pull request works on your machine? Thanks!

@michaeldfallen
Copy link
Owner

Actually it looks like it doesn't work right. So if I use ' then the prompt gets evaluated every time it renders. If I use " git-radar only renders the once, when the prompt first renders. .bashrc doesn't seem to be re-evaluated.

This might be my machine causing issues. Can you drop me your line where you set your PS1?

@grigoryvp
Copy link
Contributor Author

Indeed where are weird things. If used double quotes escape codes work correct but evaluates only once (by standard actually), and with single quotes they are messed up.

But it's something inside string returned by git-radar that mess string. If I use:

export PS1='\[\e[37m\]\W\[\e[32m\]foo\[\e[33m\] \$ \[\e[37m\]'

scape codes work fine. But if git-radar is added, its messed up:

export PS1='\[\e[37m\]\W\[\e[32m\]$(~/Documents/git-radar/git-radar --bash --fetch)\[\e[33m\] \$ \[\e[37m\]'

I don't know why this happens :(

So i used a hack that allows to use double quotes in realtime. This makes things work:

make_prompt () {
  PS1="\[\e[37m\]\W\[\e[32m\]$(~/Documents/git-radar/git-radar --bash --fetch)\[\e[33m\] \$ \[\e[37m\]"
}
export PROMPT_COMMAND='make_prompt'

@michaeldfallen
Copy link
Owner

Ok, so this superuser question explains it. PS1 converts \[ to \x01 and \] to \x02.

When you use ' to ensure your prompt gets evaluated each time, or use a \ to escape the $ in your PS1 for the same purpose:

export PS1="\$(git-radar --bash)"

then the PS1 doesn't get the chance to convert \[ to \x01 etc. The fix is to do the conversion ourselves.

I've pushed a pull request #11, can you check if that works for you? It works for me both in:

export PS1='\W\$(~/Projects/personal/git-radar/git-radar --bash) '

and

export PS1="\W$(~/Projects/personal/git-radar/git-radar --bash) "

@grigoryvp
Copy link
Contributor Author

Seems a very complicated thing. But works like a charm!

@michaeldfallen
Copy link
Owner

Awesome, thanks for the help. Closing.

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

2 participants