user2044638
user2044638

Reputation: 543

How to set the terminal title to show the current running command while it's running and to show it in brackets once it's finished?

From a different post I already know what to put in my .bashrc to set the current executing command as the terminal title:

trap 'echo -ne "\033]2;$(history 1 | sed "s/^[ ]*[0-9]*[ ]*//g")\007"' DEBUG

I would like to adjust this in a way that if there's no command currently running, the title would be a modified version of the last command, for example the whole command in square brackets (like so: [find . -maxdepth 1 -type f]).

How to achieve this?

Upvotes: 6

Views: 6832

Answers (2)

Dut A.
Dut A.

Reputation: 1168

Easy and quick way to do this on the fly:

  1. Install the program xtitle onto your PC by running this command from your terminal window: sudo apt-get install xtitle .

    • Enter your super user password when prompted.
  2. Type xtitle YOUR_DESIRED_TITLE and hit ENTER/RETURN, e.g. xtitle Tomcat will set the title to Tomcat. Repeat that command each time you want a new title.

    • NB: This was tested on Ubuntu 14.04 only.

Upvotes: 2

DrC
DrC

Reputation: 7698

You can (ab)use PS1 by putting the same escape sequence in so that every time the prompt is printed, the title gets updated.

export PS1="\033]2;[\$(history 1 | sed 's/^[ ]*[0-9]*[ ]*//g')]\007$PS1"

The final PS1 just keeps your old prompt for the actual command line.

I don't actually use this, but it should work.

Upvotes: 4

Related Questions