Ubuntu – How to make the top bar of the terminal say what command is running

command line

I often run commands in parallel that take a long time to finish and sometimes I lose track of what is running where since they output basically the same sort of information on screen.

Do you know of any way to find out what command is running in what terminal?

Best Answer

Taken from Bash - Update terminal title by running a second command · U&L and slightly changed:

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

This (ab)uses the DEBUG signal as a trigger to update the title with the last entry from your history, i.e. the last command you executed, via an XTerm Control Sequence. Add the line to your ~/.bashrc to have the feature enabled in every new terminal window.

To print other command output alongside in the title, say the current directory with pwd followed by ": " and the currently running command, I recommend using printf as follows:

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

Some terminal emulators allow you to specify a dynamic title and even give you the command name as an option so that you don't even need to fiddle around – I searched and found it in yakuake's profile settings.