Shell – Show message when cd into specific directory

cd-commandshell

How can I display a message when I cd into a specific directory? This directory is a local one, and I just need a reminder when I go into it from the terminal.

Best Answer

If I were you, I would toy around with something like that in my shell configuration file (e.g. ~/.bashrc):

reminder_cd() {
    builtin cd "$@" && { [ ! -f .cd-reminder ] || cat .cd-reminder 1>&2; }
}

alias cd=reminder_cd

This way, you can add a .cd-reminder file in each directory you want to get a reminder for. The content of the file will be displayed after each successful cd to the directory.

gim@tenebreuse ~/tmp % echo 'warning: this directory is pure junk' > .cd-reminder
gim@tenebreuse ~/tmp % cd ..
gim@tenebreuse ~ % cd tmp
warning: this directory is pure junk
gim@tenebreuse ~/tmp % 
Related Question