Konsole not responding correctly when I set PS1

When I set PS1 in konsole e.g.

PS1=“[\e[90m]\u@\h \w $ [\e[m]”

The prompt appears as

[\e[90m]\u@\h \w $ [\e[m]

When I run the same command in Terminator, the prompt appears as

jeff@y-garn ~ $

What is wrong?

If I remove the space after $ I get a prompt that is just a

>

Thanks, but that just makes

[\e[90m]\u@\h \w $[\e[m]

Are you expecting it to look like Terminator?

I’m expecting the prompt, when I open konsole to be

jeff@Snowdon ~ $

instead it’s just the literal I assign to PS1

[\e[90m]\u@\h \w $[\e[m]

Not sure If I understand correctly but:
PS1='\u@\h \W\$ ' gives me duha@archlinux ~$

There are quite a few Bash Prompt Generators out there. Some do more than others, but they all seem to work. https://bash-prompt-generator.org/ seems to work well.

Once you get it working as intended, you can put it into your .bashrc but put export in front of it.

Thanks, but but doesn’t do it for and that is why I ask the question. Is there a setting in konsole that I’m missing

I don’t remember putting in any setting to use mine. I just put the following in ~/.bashrc

#2 line color prompt (user)
export PS1="┌──[\[\e[1;33m\]\u\[\e[m\]@\[\e[36m\]\h\[\e[m\]] \d, \[\e[36m\]\T\[\e[m\] [\e[1;33m\]\w\[\e[m\]] \n└──[ <\[\e[1;5;33m\]\\$\[\e[m\]> "

and I get

Screenshot_20231120_121557

There is so much you can do with it.

I didn’t ask, are you using bash?

1 Like

Thanks all for your help. The problem seems to be a corrupt .zshrc file. I’ll play around with it

ZShell is not the same and the bash prompt doesn’t work there. That’s why asked are you using bash

I used to use ZShell, but that was a while back and I don’t remember how to help you set that one up.

For bash, you need this:

PS1='\[\e[90m\]\u@\h \w $ \[\e[m\]'

In other words, use single quotes instead of double, and most of the brackets need to be escaped (except the two after \e). Double quotes are taking the string literally.

Good catch! For some reason I was certain this is about bash. Nice prompt btw. I might steal a few things :slight_smile:

@psionman the Arch Wiki has a guide on how to set up your zsh prompt. Zsh - ArchWiki

That Arch wiki is a must have no matter what distro you run. It is a wealth of information.

@Duha I use a different prompt for root, so that it shows as red when I switch user.

1 Like

Negative on ‘export’ before PS1. It will ‘work’, and in general your environment and day-to-day usage will be ‘fine’.

However, PS1 and the like are not supposed to be ‘exported’. as subsequent shell invocations should not be inheriting those variables and/or values.

There are a number of good reasons why not… but most importantly, from my own research and experience… is that the bash environment expects PS1 to be set by /etc/bashrc----or your local .bashrc in your home directory.

Typically, .bashrc should have an exit clause early on like this:
[[ -z “${PS1}” ]] && return

This way, when PS1 is not ‘set’ (by /etc/bashrc) then the environment can depend on this shell instance NOT being a login shell, nor an interactive shell.

You run the risk of bypassing that logic by exporting PS1 specifically.

Additionally, follow the ‘example’ set by /etc/bashrc… it does not ‘export’ PS1.

Thank you.
R,
-Joe

For the sake of completeness here is my .zchrc code for my prompt and a picture. Couldn’t have done it without ou

PROMPT=$'\n'"┌─%F{black}[%F{blue}%n%F{black}@%F{blue}%m%F{black}] %F{cyan}%D{%d %b, %H:%M} %F{black}:%F{black}%~"$'\n'"└─%F{blue}$(virtualenv_info)%F{magenta}($CONDA_ENV)%F{blue} ➜ %f%b"

image