How to avoid tilde ~ in Bash prompt?

Posted by Jirka on Super User See other posts from Super User or by Jirka
Published on 2011-01-13T14:05:42Z Indexed on 2011/01/13 14:55 UTC
Read the original article Hit count: 377

Filed under:
|
|

Hello!

I have set my prompt in bash in a such way that I can use it directly in scp command:

My current PS1 string:

PS1="\h:\w\n$"

And the prompt looks like this:

lnx-hladky:/tmp/plugtmp
$

What I don't like at all is the fact that $HOME directory is displayed as tilde. Can this be avoided? It's causing problems when switching between different users.

Example:

lnx-hladky:~/DOC
$  

Documentation says:

\w : the current working directory, with $HOME abbreviated with a tilde 
\W: the basename of the current working directory, with $HOME abbreviated with a tilde

Is there any possibility to avoid $HOME being abbreviated with a tilde?

I have found one way around but I feel like it's overcomplicated:

PROMPT_COMMAND='echo -ne "\e[4;35m$(date +%T)\e[24m$(whoami)@$(hostname):$(pwd)\e[m\n"'
PS1=$

Can anyone propose a better solution? I have a feeling it's not quite OK to run so many commands just to get prompt. (date,whoami,hostname,pwd).

Thanks a lot!

Jirka

© Super User or respective owner

Related posts about command-line

Related posts about bash