Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamic window title in Urxvt with Zsh?

Tags:

terminal

zsh

x11

How can I set the window title of Urxvt to the currently running (interactive) command in Zsh shell?

For instance, if I am running journalctl, I want journalctl to be displayed as the window title. Currently the window title is just showing urxvt, which is fine if I am running no commands.

like image 899
orschiro Avatar asked Dec 22 '13 08:12

orschiro


1 Answers

This is possible with the precmd and preexec hooks. I use this for my xterm. It might work unmodified. If not, the place to tweak is the escape sequence to set the terminal title, here ESC, ], 0, ;.

case $TERM in
  (*xterm* | rxvt)

    # Write some info to terminal title.
    # This is seen when the shell prompts for input.
    function precmd {
      print -Pn "\e]0;zsh%L %(1j,%j job%(2j|s|); ,)%~\a"
    }
    # Write command and args to terminal title.
    # This is seen while the shell waits for a command to complete.
    function preexec {
      printf "\033]0;%s\a" "$1"
    }

  ;;
esac
like image 51
Jens Avatar answered Nov 15 '22 23:11

Jens