The problem is that the backticks are not substituted every magical time, but only once, so your prompt is set to whatever pwd
you were in. In order to reexecute something every time you enter a command, use function precmd()
which should reset your $PROMPT
. For example, this is a very useful function which resets your prompt according to the current directory:
function windows() {
clear
echo -e "Microsoft Windows 2000 [Version 5.00.2195]\n(c) Microsoft Corporation, 1985-2000.\n"
function precmd() {
PWD=$(pwd)
PWD=${PWD/\/usr/\/Program Files}
PWD=${PWD/\/home\/$(whoami)/\/Documents and Settings\\Administrator}
PWD=${PWD/\/home/\/Documents and Settings}
PWD=${PWD/\/sbin/\/Windows}
export PS1="C:${PWD//\//\\}> "
}
}
...or just use %~
in your PS1, like this:
PS1=' %n@%m: %~%# '
where %n
is user, %m
is host, %~
is current directory and %#
is a superuser indicator.