2

I have Fedora 20, and I would like to adapt the bash prompt to make it even more useful to me. At present my PS1 prompt is set by these lines in my ~/.bash_profile file:

 LP=" Last prompt at: "
 PS1="\[\033[s\033[0;0H\033[0;47m\033[K\033[1;34m[\$LP\]t\033[0m\033[u[<\u@\h \W>]\$ "
 echo

Which gives me a nice line at the top of the screen, with a grey bar (which does not show in this copy) and the time of the last prompt, thus:

[ Last prompt at: ]09:22:46
[<Harry@localhost ~>]$ 

Without the echo, when a terminal screen is opened, the prompt obscures the message on the top line. What the echo does is to echo its argument, so that when .bashrc. is run as a new terminal is opened, with no argument it nicely goes to a new line, leaving the top line alone. Subsequent prompts do not run .bashrc so the echo to a new line does not happen.

My question here concerns the "[ ]" brackets in the prompt round the Last prompt at: string. Please, how can I avoid these brackets appearing in the message displayed?

SOLVED
In response to @guido's answer. I had already tried just removing the square brackets, but then I lost the string completely. I note here that you have added a space after the LP, and that does indeed give me what I want, but I don't understand why the space is necessary: please could you add to your answer to explain that?

Harry Weston
  • 1,329
  • 1
    You quoted too much. – mikeserv May 27 '14 at 09:56
  • 1
    @mikeserv could you please explain that suggestion? – Harry Weston May 27 '14 at 22:23
  • 1
    But @guido already did... – mikeserv May 27 '14 at 22:31
  • There are two kinds of explanation: those that allow the experts to mod wisely, and those that make things clear to the naive enquirer. I was after the second one. – Harry Weston May 28 '14 at 09:42
  • 1
    Well, escape sequences are generally denoted by opening and closing [ square brackets ] - in combination with other characters - and these serve similarly to "quotes. It's a long string - my eyes are crossing - but you had at least one too many. Sorry for before. – mikeserv May 28 '14 at 12:43
  • @mikeserv. Thank you for that, no apology needed. I think it is the fear of seeming patronising or "talking down" that inhibits an elementary or dumbed down answer. That answers it nicely for me. I am entering an arcane and complex world, which I think I must continue to explore on my own. Thanks to all who have contributed (I know -- I am not supposed to use comments to say "thank you", but I really do want to show that I do appreciate the trouble people have taken and "one point up" seems inadequate here) – Harry Weston May 28 '14 at 14:35
  • I dunno if its any use to you - but I have one answer on prompts - it's super-simple though - nothing like this... but I did manage to avoid all of the terminal escapes - maybe there's an idea there? I dunno... http://unix.stackexchange.com/a/124904/52934 – mikeserv May 28 '14 at 16:52

2 Answers2

5

Just remove the square brackets from your PS1 (also there was a typo around \t):

LP=" Last prompt at: "
PS1="\[\033[s\033[0;0H\033[0;47m\033[K\033[1;34m\$LP \t\033[0m\033[u\][<\u@\h \W>]\$ "
echo
guido
  • 8,649
4

Guido's already answered your specific question, but just a note:

In addition, you could also set your scrolling region to be from the second line, so that scrolling doesn't erase that line.

PS1="\[\e[s\e[2;0r\e[H\e[0;47m\e[K\e[1;34m$LP\t\e[0m\e[u\]<\u@\h \W>\$ "

(though personally, I wouldn't to this kind of thing at the shell level, but for instance using screen and its hardstatus feature)