특정 디렉토리로 cd 할 때 메시지 표시 표시하려면 어떻게

cd특정 디렉토리에 메시지를 표시하려면 어떻게 해야합니까? 이 디렉토리는 로컬 디렉토리이므로 터미널에서 디렉토리를 열 때 알림이 필요합니다.



답변

내가 당신이라면 내 쉘 구성 파일 (예 :)에서 다음과 같이 장난감을 가지고 놀 것입니다 ~/.bashrc.

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

alias cd=reminder_cd

이렇게 .cd-reminder하면 알림을받을 각 디렉토리에 파일을 추가 할 수 있습니다 . cd디렉토리에 성공한 후 파일의 내용이 표시됩니다 .

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 %