Comments (12)
I am unable to reproduce this. My strong suspicion is that you have not wrapped your color codes in \[
and \]
for bash (or %{
and %}
for zsh). This Stackoverflow post has a well-written explanation of this problem. Could you please paste the exact mumbo jumbo used to set PROMPT_COMMAND
?
from posh-git-sh.
Here's the exact code.
export PROMPT_COMMAND='__posh_git_ps1 "\[\e[00;37m\]\u@💻 \[\e[00;31m\]\w" "\[\e[00;37m\] \$ \[\e[00m\]";'$PROMPT_COMMAND
I know bash does not know the number of printable and unprintable characters, so those should be grouped in \[
and \]
. I guess the grouping I currently have is correct, but if you spot any error I'd like to know!
I figured it could be caused by some quirk concerning the laptop emoji 💻 I use. Because it prints in a different font (because my monospaced console font, Source Code Pro, does not support it) it is wider than the terminal font and requires two spaces after the character. However, I tried replacing it with \h
and the results did not change.
I conclude that a line breaking in the middle of or near the posh git string may cause the incorrect wrapping problem.
from posh-git-sh.
After a little bit of poking around, it just seems that the particular emoji doesn't play nicely at all with the terminal. I opened up a boring terminal prompt, pasted it in. It caused havoc to my prompt if I tried to edit the line and if it was a long line. This feels like a limitation in bash or the terminal emulator. Can check that taking out the emoji eliminates the problem?
from posh-git-sh.
@lyze As I said in my previous comment: I can reproduce the problem without the emoji, so the issue isn't caused by it.
from posh-git-sh.
I can't reproduce the problem when using \h
on my own computer. (Caveat: It wasn't on a Mac, and I don't have a Mac handy to test.)
The actual expansion of PS1
with \h
:
\[\e[00;37m\]\u@\h \[\e[00;31m\]\w\[\e[1;33m\] [\[\e[1;36m\]master ≡\[\e[1;33m\]]\[\e[m\]\[\e[00;37m\] $ \[\e[00m\]
I can't see anything wrong with it.
I'm really scratching my head here. Some theories that I would need you to help investigate:
- Is there anything else in
$PROMPT_COMMAND
that might mess with$PS1
? - Have you tried setting
shopt -s checkwinsize
? - Try messing with the terminal emulation settings? I think it's "Preferences > Advanced > Emulation".
- Try using
tput
instead of ANSI colors.
from posh-git-sh.
Great ideas! Here are my results. (spoiler: no luck...)
- Yes, my
$PROMPT_COMMAND
contains (before prepending my posh Git string):update_terminal_cwd
. Removing it does not change the issue. - It was already set and explicitly setting it does not change the issue.
- How do I do this? Is it under Prefs > Advanced > Terminfo (where it says xterm-256color by default)? I tried about 5 different values there and it does not change the issue.
- Currently, my
$PROMPT_COMMAND
implementation is:
red=$(tput setaf 1)
gray=$(tput setaf 8)
reset=$(tput sgr0)
export PROMPT_COMMAND='__posh_git_ps1 "\[$gray\]\u@\h \[$red\]\w" "\[$gray\] \$ \[$reset\]";'$PROMPT_COMMAND
The issue persist, unfortunately.
Even when using export PROMPT_COMMAND='__posh_git_ps1 "\u@\h \w" " \$ ";'$PROMPT_COMMAND
or export PROMPT_COMMAND='__posh_git_ps1 "foo bar" " baz qux ";'$PROMPT_COMMAND
does not change the issue.
from posh-git-sh.
If you clear PROMPT_COMMAND
and only set PS1
, does the problem still occur?
PROMPT_COMMAND=
PS1=\[\e[00;37m\]\u@\h \[\e[00;31m\]\w\[\e[1;33m\] [\[\e[1;36m\]master ≡\[\e[1;33m\]]\[\e[m\]\[\e[00;37m\] $ \[\e[00m\]
from posh-git-sh.
Using
PROMPT_COMMAND=
PS1='\[\e[00;37m\]\u@\h \[\e[00;31m\]\w\[\e[1;33m\] [\[\e[1;36m\]master ≡\[\e[1;33m\]]\[\e[m\]\[\e[00;37m\] $ \[\e[00m\]'
(i.e. what you said, but with 'quotes')
the results are the same. Something is wrong in the way Terminal wraps a line with grouping of non-printable characters. I think the line break it should insert ends up erroneously within the unprintable group, so it gets ignored somehow.
I guess this rules out posh-git-sh as the culprit, don't you agree? Where do I go next with this issue? The current behaviour is ok if the Terminal window does not have the problematic width (which is one of two or three widths depending on the length of $PS1
when it prints).
I guess I'll have to resort to a Terminal alternative.
from posh-git-sh.
I'm out of ideas at the moment. By now, I, too, am fairly confident that posh-git-sh isn't the culprit here.
A long shot. Do you think you need to update bash or Terminal itself?
Also, I think you may want to consider filing an Apple bug report.
from posh-git-sh.
I work on Terminal v2.7.1 (387), which is the latest stable release according to Wikipedia at the moment of writing. Also, I'm running Bash v4.4.5(1)-release (echo $BASH_VERSION
), again, the latest stable version according to Wikipedia.
I'll contact Apple about the issue.
from posh-git-sh.
Thanks for taking the time to look into this! 👍 I hope I'll find a solution for this (and if so, I'll report back here).
from posh-git-sh.
I've opened a discussion thread here.
from posh-git-sh.
Related Issues (20)
- When will posh-git-sh retrieve git status automatically? HOT 2
- Can posh-git-sh work for iterm2 terminal? HOT 4
- ZSH HOT 5
- Hide status symbol when no upstream exists HOT 1
- Consider Numeric Indicator of Commits Ahead/Behind HOT 1
- output='' error information will show in shell prompt HOT 1
- Strange $17 at the end of the prompt HOT 7
- acceptance tests and continuous testing HOT 1
- Show conflicting and unstaged state (! and ~) HOT 1
- Bash 5 warning: ignored null byte in input HOT 1
- zsh instructions don't appear to work in macOS Catalina HOT 2
- Very slow compared to Powershell posh-git HOT 7
- zsh : issue with escape sequence introduced by #47
- Unstaged changes don't have exclamation HOT 2
- 1
- Please add a license file HOT 2
- break Python virtualenv display HOT 3
- Don't display anything, when there is no upstream
- simple instructions for zsh
- Shell option `failglob` results in errors during prompt rendering HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from posh-git-sh.