Showing current directory in Terminal’s title, using tcsh

terminal

I'd like the title bar of Terminal to always show the directory I'm in. I don't want it shown in the prompt. I found some magic trick code online, and have this in my .tcshrc:

set prompt = "%B%m:%n %?====>%b "
alias cwdcmd 'echo -ne "\033]0;$cwd\007"'

It sort of works except for two things: 1) the cwd isn't shown in the title bar, and 2) the cwd along with some gibberish is printed at the command line. I figured maybe the quoting wasn't right, or some other syntax issue, but experimenting didn't lead to improvement.

For reasons unspecified, I must use tcsh not bash. The latter, I can get working fine.

Best Answer

This is what I have in my .cshrc

alias cwdcmd 'printf "\033]1;%s\007\033]2;%s\007" "$cwd:t" "$HOST echo $cwd | sed s-$HOME-~-" '

It does some additional stuff for iTerm, which I use instead of Termial, but seems to work fine there as well.