flashburn
flashburn

Reputation: 4528

remove hyphen in bash prompt

My bash PS1 prompt is configured as:

export PS1="\e[1;38;5;120m\\n\s \V\\$ \e[0m"

It looks like

-bash 5.0.7$

Having the hyphen, -, in front of bash is quite annoying. Does anyone know how I can get rid of it?

Upvotes: 2

Views: 153

Answers (2)

chepner
chepner

Reputation: 531808

The - appears because the login program runs your default shell with a prefixed - to indicate that a login shell should be used (equivalent to bash -l).

\s is essentially just a synonym for basename "$0". If you can't easily change how your shell is run in the first place, you can modify your prompt to strip the - from $0 instead.

PS1="\e[1;38;5;120m\\n${0#-} \V\\$ \e[0m"

(Unless you specify otherwise, I'll assume no other processing of $0 is needed.)

Upvotes: 3

Google Fail
Google Fail

Reputation: 113

Maybe not exactly what you had in mind, but replacing \s with literal text bash will do that:

export PS1="\e[1;38;5;120m\\nbash \V\\$ \e[0m"

Setting the prompt like this wouldn't work for other shells anyway.

Upvotes: 2

Related Questions