Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get ZSH to display the current directory in the Terminal frame?

I'm gradually switching from Bash to ZSH, and trying to learn by replicating features. Can't seem to find this one though.

Bash does this by default I think

What should I put, and where should I put it? Is this even possible? Thanks.

like image 950
Kevin Suttle Avatar asked Dec 27 '22 23:12

Kevin Suttle


1 Answers

Try this:

settitle() { printf "\e]0;$@\a" }
dir_in_title() { settitle $PWD }
chpwd_functions=(dir_in_title)

Now, your cd commands will run the dir_in_title function, which will print an escape sequence that asks Terminal.app to update the title. (Oddly enough, using an escape sequence that also works in urxvt, at least. These must be more standardized than I expected.)

If you like the effect, you'll need to add these lines to your ~/.zshrc for it to work on future terminals.

I grabbed the correct escape sequence from Chris Page on superuser and the style of functions from my answer to similar but different question. Chris Page gave his own answer on that question with details on OS X 10.7 that are drastically different. When you upgrade you'll probably want to use his mechanism instead.

like image 190
sarnold Avatar answered Jan 05 '23 15:01

sarnold