Question

How we can automatically change the terminal title as current directory name. I have below command in my cshrc file

alias precmd 'echo -n "\033]0;${PWD}\a"'

But it is displaying the full path instead of current directory path. So I wants to update the title with current directory.

Also please Let me know if we can display the title with current directory plus its parent directory name?

for example if the full directory path is /user/shibin/code/cpp/ I need to change the terminal name as either /cpp or /code/cpp

Thank You

Était-ce utile?

La solution 2

FYI,

If you wants to set the terminal title as /code/cpp in my above question, do this :

alias precmd 'echo -n "\033]0;`pwd | rev | cut -d/ -f1,2 | rev`\a"'

if you change the filed from -f1,2 to -f1,3 then you can set the title as shibin/code/cpp and so on...

Autres conseils

You can get the last element from a directory path with basename(1), so the following should work with tcsh:

alias precmd 'echo -n "\033]0;`basename ${PWD}`\a"'
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top