3

I want, that my terminal tabs have the current working directory as the tab-title and the terminal window have the current working directory of the "active/in front" tab as their window-title.

I can manually set the window title for all the current and all new windows in the preferences dialog. I can manually set the tab title for the current tab with rightlick->change tab title.

Is there a preference for newly created tabs?

Everything above has the problem, that the value does not update after a cd. Is there any built-in way from xfce4-terminal to do this automatically?

Without an automatic solution the titles are mostly useless for me :/

Follow-Up: Can I use something like the last executed command as the tab/window title? Seems to me, there is no built-in substitution for this.

1 Answers1

3

Changing your bash prompt like so:

export oldprompt=$PS1
export PS1="\[$(xtitle \`pwd\`)\]$oldprompt"

Will cause the title of your terminal/tab to interactively display the current working directory. To discontinue, undo with export PS1=$oldprompt.

Adding these two lines to the end of your ~/.bashrc or ~/.profile will set this up for every new terminal or tab you open.

For your follow-up, you can get the last executed command displayed in your title by using this prompt instead:

export PS1="\[$(xtitle $BASH_COMMAND)\]$oldprompt"

The word "xtitle" appears before the command; this could be further finessed by calling a script that strips it out, but I think there's a point of diminishing returns.

(Previously, this answer only included the workaround-solution below...)

An (admittedly inelegant) solution can be had (at least in bash) with the following:

function cwd { cd "$@" ; xtitle `pwd`; }

Enter this at your prompt to register the function, then interactively try out the resulting cwd command which will change directory and update your terminal's tab/titlebar. (If you forget and use cd instead, you could always type cwd by itself to just update the tab/titlebar.)

If you decide this works for you, place that line at the end of your ~/.bashrc to give it some permanence.

(If you don't have xtitle installed, then use your local equivalent of sudo apt-get install xtitle or yum install xtitle.)

Benjamin Staton
  • 501
  • 2
  • 9
  • I'm trying to get only the basename and have export PS1="\[$(xtitle '\${PWD##*/}`')]$oldprompt"but that always display'around the title. https://stackoverflow.com/a/1371283/205696 I also tried to usebasename` I do not know how to escape properly. – dotnetCarpenter Nov 11 '18 at 16:11