1

sorry for the title, I have no better way to convey what is occurring to me. The situation is the following, I am using bash, wezterm(terminal emulator) and starship (customizable prompt). But for some reason, every time I open a new terminal, it is always the stock/ default prompt, and I have to press enter or type something for it to pickup the updates. I have no idea what kind of behavior is happening here

image of terminal showing the problem

As you can see, the first line is the line that has no styling applied, while the second line is how its supposed to look.

My observations are the following

  1. This always happens when opening a new terminal
  2. This does not seem to happen when I ssh into this machine
  3. This does not happen when I open a new terminal inside a terminal via multiplexer like zellij

The weird thing is, that it works properly after typing anything. This is why I have no idea how to debug this. There is probably something weird happening that I am not aware of how it works.

My bash setup can be found here, but I'll outline the most important files here

my bash_profile which just sources my .bash_rc

source ~/.bashrc

My .bashrc

# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# If not running interactively, don't do anything

if [ -e ~/.bash_aliases ]; then
    source ~/.bash_aliases >/dev/null 2>&1
fi

case $- in
*i*) ;;
*) return ;;
esac

.. truncated, other stuff is the default that comes in bashrc basically

And finally my .bash_aliases

unalias -a
set -o vi
...

# Have to install bash-preexec as well
[[ -e ~/.bash-preexec.sh ]] && source ~/.bash-preexec.sh

# here are the evals and they are 100% evaluated
source ~/.config/wezterm/wezterm.sh
eval "$(starship init bash)"

[[ -e ~/.config/personal/bash/alias_personal ]] && \. ~/.config/personal/bash/alias_personal

This also might be an issue with the library itself, but I highly doubt this. This behavior started occurring after I was fiddling with my config, its been months now.

7
  • echo "$PROMPT_COMMAND" please Commented Nov 23, 2023 at 21:40
  • 1
    First, please do not post images of text. Next, since you are sourcing another file and running an eval on the command (don't get me started on that), we do need to see what you are sourcing.
    – doneal24
    Commented Nov 23, 2023 at 21:53
  • have you tried it with another terminal emulator? my guess is thats the cause
    – Junaga
    Commented Nov 23, 2023 at 23:30
  • 1
    @doneal24 this is not an "image of code" but an screenshot of an application, the app he is having trouble with.
    – Junaga
    Commented Nov 23, 2023 at 23:40
  • 2
    @Junaga A terminal emulator that does not allow for text to be copied to the clipboard sounds unusual. You can call any terminal emulator, text editor, etc. an application but the general consensus on U&L is that you need to cut & paste if it is possible to do so. Also, my comment did not use the phrase "an image of code" nor did the link I pointed to so I am not sure what you are referring to by that.
    – doneal24
    Commented Nov 24, 2023 at 19:05

2 Answers 2

3

I know this one is pretty old, but in case anyone else finds this while trying to resolve the same issue, Chris Davies is 100% Correct. Because the prompt is set via the precmd function, this normally requires SOME sort of interaction occur.

However, the easiest resolution is to execute that precmd on initialization.

I sorted this by adding the starship_precmd directly after initializing starship.

In your case Nikola, this mnodification to your .bash_aliases should solve the issue:

unalias -a
set -o vi
...

# Have to install bash-preexec as well
[[ -e ~/.bash-preexec.sh ]] && source ~/.bash-preexec.sh

# here are the evals and they are 100% evaluated
source ~/.config/wezterm/wezterm.sh
eval "$(starship init bash)"

# Execute the precmd to set initial PS1
starship_precmd

[[ -e ~/.config/personal/bash/alias_personal ]] && \. ~/.config/personal/bash/alias_personal
1
  • Thank you for explaining how to resolve the issue Commented Aug 13 at 10:07
2

Starship applies its configuration each time you execute any command (see starship init bash --full-code-print for one example of it setting up $PROMPT_COMMAND) but as far as I can see not in the .bashrc or .bash_profile. Aside from the incredible inefficiency this incurs, it also means that the prompt cannot be set until you execute a command. A null command (i.e. hitting enter by itself) is acceptable here, but the point is that you need to do something.

It is how it is.

Personally, if all I wanted was a fancy prompt then I'd set that directly in ~/.bashrc (and have ~/.bash_profile call it on login).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .