Quote:
Originally Posted by unipepper
Hi,
I want to change my command prompt to contain the current username and the current directory in it, instead of just the '$' symbol.
I tried the command:-
export PS1="[$(whoami) $(pwd)]$(echo \\n$) "
But whenever I switch the user or change the directory, the changes are not reflected in the command prompt. Could anyone pls help me?
Thanks in advance.
"cd" is a build-in command so you will need to create a wrapper around "cd" in order to achieve it - which means u need to "alias" cd.
So, something like this "may" solve your problem (thats what I thought atleast)
alias cd='cd \!*; export PS1="[$(whoami) $(pwd)]$(echo \\n$) "'
But the issue is you cannot pass arguments in k-shell so, "cd \!*" wouldn't work.
This would be possible in csh I guess.
You will need to enclose this in a function and then alias "cd" to the function name:
So, in your .profile do this like:
------
export PS1="[$(whoami) $(pwd)]$(echo \\n$) "
function newcd {
"cd" "$@"
ret=$?
export PS1="[$(whoami) $(pwd)]$(echo \\n$) "
return $ret
}
alias cd=newcd
------
Enjoy !