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

Extra space added after prompt when using tmux #8

Closed
Jehops opened this issue May 15, 2019 · 7 comments
Closed

Extra space added after prompt when using tmux #8

Jehops opened this issue May 15, 2019 · 7 comments

Comments

@Jehops
Copy link
Contributor

Jehops commented May 15, 2019

Hello Wolfgang,

With this simple recipe, an extra space is added after the prompt when a tmux session is attached and $PWD is a Git repository. This is with an empty tmux configuration and only these two lines in ~/.zshrc.

>  cat ~/.zshrc
source /usr/local/share/git-prompt.zsh/git-prompt.zsh
PROMPT='$(gitprompt)> '
  1. start terminal application (prompt has one space after >)
  2. cd some_git_repo (prompt shows git status and still one space after >)
  3. cd ~/
  4. tmux (prompt still shows one space after > )
  5. cd some_git_repo (prompt now shows two spaces after >)
> uname -a
FreeBSD phe.ftfl.ca 12.0-RELEASE-p3 FreeBSD 12.0-RELEASE-p3 GENERIC  amd64

> pkg info -q | grep '^zsh-[0-9]\|^git-[0-9]' 
git-2.21.0
zsh-5.7.1

Thanks for creating git-prompt.zsh. The asynchronous Git status is nice.

@woefe
Copy link
Owner

woefe commented May 16, 2019

I cannot reproduce it.

Can you please check if following commands produce different output depending on whether you run them in tmux or not. If it produces the same output, it is probably not related to the prompt itself.

cd some/git/repo
print -P $(_zsh_git_prompt_git_status) | wc -c

The issue could be related to your terminal or your tmux setup. Most likely, the issue has to do with the special Unicode characters (✔,●, ⚑, etc.) that are used in the prompt. They somehow confuse your terminal. You can try using ASCII only characters and see if the problem goes away:

ZSH_THEME_GIT_PROMPT_UNMERGED="x"
ZSH_THEME_GIT_PROMPT_STAGED="o"
ZSH_THEME_GIT_PROMPT_UNSTAGED="+"
ZSH_THEME_GIT_PROMPT_UNTRACKED="..."
ZSH_THEME_GIT_PROMPT_STASHED="F"
ZSH_THEME_GIT_PROMPT_CLEAN="/"
source /usr/local/share/git-prompt.zsh/git-prompt.zsh
PROMPT='$(gitprompt)> '

If none of the above helps, I need more info:

  • what terminal do you use and which version?
  • which version of tmux (tmux -V)?
  • Do echo $TERM inside and outside of tmux

@Jehops
Copy link
Contributor Author

Jehops commented May 17, 2019 via email

@woefe
Copy link
Owner

woefe commented May 17, 2019

Okay. I think there is no extra space character, because it works with ASCII characters. xterm or urxvt probably don't handle the special characters correctly and render it weirdly. To confirm this suspicion you could try copy/pasting the prompt into e.g. Firefox and see if there is one or two spaces.

Some more ideas:

  • You could try changing the font.
  • I have (old) xterm and urxvt configs here. I could not reproduce the issue with these configs. You could try them.
  • As a last resort try another terminal emulator. I personally moved to Alacritty. I like it much more than xterm or urxvt.

@Jehops
Copy link
Contributor Author

Jehops commented May 18, 2019

I see the same behavior with alacritty, but since the problem does not happen in any of alacritty, urxvt, or xterm except under tmux, I wonder if the problem is with tmux.

I only mentioned the extra space, because it is the most obvious and consistent problem, however, at times, input after the prompt is not displayed correctly until after refreshing the screen (with Control-l).

Thank you for looking into this with me. I will close this issue now now and refer to it when I submit an issue with tmux.

@Jehops Jehops closed this as completed May 18, 2019
@woefe
Copy link
Owner

woefe commented May 18, 2019

Yeah, from what we have seen so far it seems to be a tmux problem.

I have two more ideas.

  1. From zshall manpage:

    %{...%}
    Include a string as a literal escape sequence. The string within the braces should not change the cursor position.

    Make sure that you do not put characters between %{ and %}, but only escape sequences for e.g. colors (unless you add "glitches" with %G). I did this once and it lead to behavior similar to what you are describing.

  2. Maybe something goes wrong when the prompt is refreshed asynchonously. You could try the following, which makes the prompt synchonous:

    source path/to/git-prompt.zsh
    add-zsh-hook -d precmd _zsh_git_prompt_precmd_hook
    PROMPT='$(_zsh_git_prompt_git_status)> '
    

@Jehops
Copy link
Contributor Author

Jehops commented May 19, 2019

  1. The issue exists with just the following lines in .zshrc, so I assume the string literals are not the issue.
source /usr/local/share/git-prompt.zsh/git-prompt.zsh
PROMPT='$(gitprompt)> '
  1. The problem also occurs with the synchronous prompt.

@Mellbourn
Copy link

I have a similar problem. When I enter a Raspberry pi using SSH, and cd into a git repo, the left hand prompt seems to get two left cursor keys. So that the cursor now overlaps the left hand prompt (I have the git prompt in RPROMPT)

A workaround is to replace the special unicode characters with ordinary ASCII 7 characters. But that doesn't look as good.

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

3 participants