caiogondim / bullet-train.zsh

:bullettrain_side: An oh-my-zsh shell theme based on the Powerline Vim plugin
MIT License
2.82k stars 383 forks source link

Feature request: Omit the first new line #156

Open luiscobot opened 8 years ago

luiscobot commented 8 years ago

Can you make this improvement? Delete the first new line before first prompt line see: luisco luis-romero 2016-07-16 21-54-33 I want the new line, but after of first command. Thanks

dawikur commented 8 years ago

Is this occurring only at the first line on at every prompt?

luiscobot commented 8 years ago

@dawikur I want the new line on every prompt, but the new line at the first prompt seem rare because it adds an unnecessary line. I know 'BULLETTRAIN_PROMPT_ADD_NEWLINE' but what I want is omit the first new line if it could

dawikur commented 8 years ago

BULLETTRAIN_PROMPT_ADD_NEWLINE option adds newline after prompt, not before; so you ffirst new line rather is not caused by it. Maybe you have something in your zshrc file that is producing this line?

stevensonmt commented 7 years ago

+1 on this issue. Setting BULLETTRAIN_PROMPT_ADD_NEWLINE=(false) removes the newline from the top of the terminal but then I'm stuck with a cramped terminal after a few commands.

jep-dev commented 7 years ago

+1 from me as well - tried it from a new user with a bare-bones zshrc (oh-my-zsh, bullet-train + add_newline false) and the error persists. To be clear: "echo" moves the prompt three lines down; "" moves it two lines down. For comparison, powerlevel9k does not have this issue, even though it has a RHS prompt flush with the last column, which you might think would cause an extra newline in some contexts. Strangely, switching from powerlevel9k to bullet-train seems to fix the issue, while any new prompt starts with the extra newline (until switching the theme to powerlevel9k and back.) I tried several other prompts, but only powerlevel9k has fixed it so far.

As a workaround, you could set the theme to powerlevel9k, source oh-my-zsh, set the theme to bullet-train, and source it again. This worked for me. If sourcing oh-my-zsh twice causes other errors, set a flag after the first source and use the flag to disable all but the theme component of your oh-my-zsh script.

Edit -- this workaround isn't perfect, powerlevel9k has other effects on the prompt. I'll update if I figure anything out.

jep-dev commented 7 years ago

Here is my current solution: ~/.zshrc

PS1=${PS1//\n//}
SOURCED_ZSHRC=${SOURCED_ZSHRC:-0}
let "SOURCED_ZSHRC++"
export SOURCED_ZSHRC
if [ "$SOURCED_ZSHRC" -lt 2 ]; then source ~/.zshrc; fi

I'm not sure why I need to source it twice; for the root instance, once is enough, but for splits, zshrc is definitely sourced but PS1 is not stripped. I will dig through zsh's verbose mode a bit later to see where the newline might be added.

jep-dev commented 7 years ago

I can't seem to find where and how the newline is added, but instead of sourcing twice, I have added a few lines after sourcing oh-my-zsh:

export PROMPT="$(tr -d '\n' <<< $PROMPT)"
export PS1="$(tr -d '\n' <<< $PS1)"
...
export PS4="$(tr -d '\n' <<< $PS4)"

If anyone else would like to do more digging, I was using the following method:

  1. Turn on Tmux logging (<prefix><:> pipe-pane -o "exec cat >> temp.txt")
  2. Run zsh -v
  3. Turn off Tmux logging (<prefix><:> pipe-pane)
  4. Exit (zsh -v is still running)
  5. Inspect temp.txt for uses of echo without echo -n, newline characters, etc.
vadviktor commented 7 years ago

None of my Linux terminals have such an issue. Also, PS1 and others are BASH prompts, not ZSH ones.

jep-dev commented 7 years ago

Sorry I didn't update, but at some point I tried Bullet-Train again, and I don't have this issue anymore. I had removed the include guards around oh-my-zsh.sh and the prompt filters before switching back to BT, but left the counter in place; now that I've switched back, whether the counter is 1 or not, BT is honoring the ADD_NEWLINE value. It's my fault for not logging more information when I had the issue, because I've migrated my dotfiles across several kernels, versions of Tmux, etc. and I have no way of reproducing the issue since I never figured out what was even relevant. I'm pretty sure I only set those Bash prompt filters after exhausting all the sane approaches I could think of, and maybe I saw oh-my-zsh.sh and took a shot in the dark. Generally if I find a 'solution' I try to regress each change, too, so if the Bash prompt filters were actually necessary, I have even less of an idea what was wrong with my setup.

Currently, I'm on Linux 4.10.0-30, using Zsh 5.1.1. Is anyone still experiencing this issue?