Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have made my command prompt ($PS1) to be just username.../current_directory (using the 3 dots because my directory structure has lots of levels and they were taking up too much of the command line prompt).
However this would work better if, when I cd'd into a directory, the cd command showed what directory I get changed into. How can I have this happen?

btw my command prompt setting (that I don't wish to change) to do username...current_dir is:

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
    PS1='${debian_chroot:+($debian_chroot)}\u.../${PWD##*/}\$ '
fi
share|improve this question

1 Answer 1

up vote 10 down vote accepted

With zsh

chpwd() pwd

Then, the current directory is printed whenever it changes (upon cd, pushd, popd...).

With ksh, bash or zsh:

cd() {
  builtin cd "$@" && pwd
}

(you'd typically put those in your shell configuration file)

share|improve this answer
    
Another tip you may want to add: in bash, setting CDPATH=. is another method to achieve what the OP wants. –  jw013 Nov 14 '12 at 14:52
    
@jw013, nice trick about CDPATH, however that doesn't output the path for cd /absolute/path (which is probably what the OP wants) or cd ./foo or cd .. or cd ../bar –  Stéphane Chazelas Nov 14 '12 at 15:05
    
That is true. It is enough to cover 99% of the cases for me. I rarely need to see the full path if I am already using an absolute path argument to cd, and when I use ./ or .. I generally already know where I am. –  jw013 Nov 14 '12 at 15:10
    
Accepted, works great (bash). –  Michael Durrant Nov 14 '12 at 16:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.