How can Console2 use the current directory as the name of a bash tab?

4

2

Is this possible at all? (basically a pendant to cmd.exe's title command that Mikel's answer mentions, although I'd prefer changing the entire tab name instead of adding a window title)

Tobias Kienzler

Posted 2011-01-20T12:16:25.530

Reputation: 3 262

Answers

4

In bash, the standard Xterm sequences documented at How to change the title of an xterm seem to work, e.g.

echo -e "\033]0;custom title\007"; cat

So try adding that to your PS1 in your .bashrc or whichever config file you use, e.g:

PS1="\033]0;\$PWD\007$PS1"

or use PROMPT_COMMAND instead if you are using bash.


In cmd.exe, you can use title <string> to set the title.

You would chain it together using a doskey alias like this:

doskey cd=title $1 ^&^& cd $1

Then set it to load for every new cmd using the instructions in Loading DOSKEY Automatically with CMD.


In both cases, to show only the window title, go to Settings->Appearance and tick the
Use console window title* box.

Mikel

Posted 2011-01-20T12:16:25.530

Reputation: 7 890

I'm afraid title is a built-in of cmd.exe, so bash claims bash: title: command not found :( but it works for cmd.exe, so +1 – Tobias Kienzler – 2011-01-20T12:41:49.933

thanks for the update - wow, doskey's still around? Hm, I'd probably first of all doskey alias=doske – Tobias Kienzler – 2011-01-20T12:51:59.060

Yes, my original answer was only for cmd. I have updated it with instructions for bash. – Mikel – 2011-01-20T12:58:49.410

your current solution won't change the working directory, using PS1='\033]0;\u@\h:\w\007'$PS1 instead does the trick – Tobias Kienzler – 2011-01-20T13:17:06.007

Sorry, yes, there was a missing backslash. It is fixed now. – Mikel – 2011-01-20T13:18:53.713

@Tobias: fwiw, these days doskey is just a thin wrapper around Console API. – user1686 – 2011-01-20T14:09:47.373

1

Been a while, but the only post that mostly answered my problem
Building on the answer from Mikel and the comment from Tobias, adding

PS1='\[\033]2;\u:\w\007\]'$PS1

to ~/.bashrc allowed consoleZ (successor to console2) to show the shell title in the consoleZ tab, and not mess up line wrapping in the shell.

"Note the use of \[...\], which tells bash to ignore the non-printing control characters when calculating the width of the prompt. Otherwise line editing commands get confused while placing the cursor."
http://www.faqs.org/docs/Linux-mini/Xterm-Title.html#ss4.3

browniebytes

Posted 2011-01-20T12:16:25.530

Reputation: 11