Score:0

Troubles with custom bash prompt

se flag

I am trying to set a custom bash prompt to also include history line count and time in 24h format, both in different colors, aside from a standard user@host prompt.

I have seen this post

Custom bash prompt is buggy

and some other examples, but I still seem to be unable to make it right, since I experience all kinds of weird behavior after setting the custom prompt.

I have tried several variations of this string:

PS1='\[\e[01;31m\]\!\[\e[00m\] \[\e[01;33m\A\[\e[00m\] ${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '

some with less and some with more escape characters. Various trials result in either too much or too little text when browsing history or deleting a command on a line.

Even by looking at several examples, I cannot get, what needs to be escaped and how much.

It is probably not relevant, but I am using Kubuntu 21.10. I only access bash through Konsole and Dolphin terminal.

Thank you in advance and Kindest regards!

Bostjan Murovec avatar
se flag
Thank you for providing a solution. However, it still does not work. When I browse commands in history with arrow up / arrow down, a few characters from the end of command prompt disappear. I have tried it also in Fedora 35. This is precisely the trouble that I could not resolve.
Score:0
se flag

This seems to work. It is trivial. I have no idea why I could not make it before.

PS1='[\033[01;31m]![\033[00m] [\033[01;33m]\A[\033[00m] ${debian_chroot:+($debian_chroot)}[\033[01;32m]\u@\h[\033[00m]:[\033[01;34m]\w[\033[00m]$ '

I apologize for posting such a trivial problem.

Anyway, I find this prompt very useful, so here is the solution anyway for anybody interested in it.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.