0

I wanted to use the set-title function from https://askubuntu.com/a/774543/435408 to make the terminal title into a sort of status bar. That way I can see in the GUI whether my server is Running or Complete.

set-title Running && doStuff.sh && set-title Complete

With this code, you never see the title change to "Running", only "Complete". I believe this is because the title only changes when the system reads PS1 to make a new prompt, after all three commands run.

I got "Running" to show right away by putting the other commands in the background:

doStuff.sh && set-title Complete & set-title Running; fg

But then the terminal title was never set to "Complete" because that call was in the background. "fg" didn't help.

I had similar problems with

set-title Running; echo "doStuff.sh; set-title Complete" | at now + 0 minutes

Finally, I tried opening a new terminal tab titled "Running", as per https://askubuntu.com/a/860484/435408, but I was not able to pass any commands to the bash session to set its title to "Complete". The tab closes right away if I try using --rcfile or -c.

gnome-terminal --tab -e "bash -c 'printf \"\033]0;Running\007\"; sleep 4; exec bash'"
0

I got the behavior I wanted like this:

  1. Use gnome-terminal to create a window with the "Running" title
  2. Keep the window open after execution by calling exec bash
  3. Put the call to "set-title Complete" in a file called ~/.statusrc which I passed to the new bash.
gnome-terminal --maximize --title="Running" -- /usr/bin/bash -c \
". /home/user/.bashrc; doStuff.sh; exec bash --rcfile /home/user/.statusrc"

The ~/.statusrc file looked like this:

#!/usr/bin/bash

. ~/.bashrc
termtitle "Complete"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.