Bash: show the currently running command in the window title

I was just learning for an exam (and taking glimpses at irssi) when a thought hit me: “wouldn’t it be nice if Terminator showed the currently running command in the window’s title”.

So, I asked Google and found a pretty nice post on how to do it. At first the proposed solution resulted in some weird messages being printed, but just changing the order of a line fixed it, so here’s the working code for bash in Ubuntu Intrepid:

if [ "$SHELL" = '/bin/bash' ]
then  case $TERM in

rxvt|*term)

set -o functrace

export PS1="\e]0;$TERM\007$PS1"

trap 'echo -ne "\e]0;$BASH_COMMAND\007"' DEBUG

;;

esac

fi

Pretty nice, eh? Now, if someone’s up for a challenge: if it showed the command being executed inside screens instead of just “screen -r” that would be even greater.

Edit: And if someone knows how to get Wordpress to display the messages properly that would rock.

Edit 2: I’ve just noticed that this breaks tab completion, so it’s not that nice after all.

6 Comments »

 
  1. oliver says:

    You could use centerim / centericq – even inside screen, it shows something like “centerim: event from [irc]…” etc. in the window title :-)

  2. RainCT says:

    oliver: Well, but this is not only for IRC but for any command (and I’m happy with irssi), but thanks :).

  3. Enric says:

    Hola,
    participaràs a l’olimpiada d’informàtica? T’ho recomano, val molt la pena i s’aprèn moltíssim.

    Com és que no vas participar al concurs de benvinguda?

    Salutacions,
    Enric S. Cusell

  4. RainCT says:

    Hola Enric,

    He començat a fer les pràctiques però dubto que participi en les proves.

    És el primer cop que faig alguna cosa amb C++ (o amb qualsevol altre llenguatge d’aquest tipus) i de moment tardo varies hores per fer un sol exercici.

    Però bé, encara queda temps fins a l’abril així que fins llavors potser ja hauré après alguna cosa i tot :).

  5. Enric says:

    Jo tampoc en sabia. Et recomano participar a tots els concursos, encara que només facis el primer problema o ni tan sols això.

    S’aprèn molt, si és que t’agrada.

    Fins aviat,
    Enric S. Cusell

  6. [...] posts but then leave them for later until they are no longer interesting (except when it’s a stupid post, then I publish it within minutes ;)). Anyway, before this happens again, here you have some [...]

 

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>