Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 895
user2044638 Avatar asked Jun 06 '13 23:06

user2044638


1 Answers

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.

like image 192
DrC Avatar answered Nov 02 '22 00:11

DrC