irssi in a screen session via ssh


  • have irssi running permanently on a server in a screen session.
  • auto-connect to this session from a client on X startup.
  • set un/away when
    • the screen session is detached/re-attached.
    • xscreensaver is de/activated on the client.
  • open URLs on the client (a graphical browser has its merits nowadays ...).

on the server

  • obviously irssi & screen need to be installed & configured, xauth (from xbase-clients) is needed for the URL fun as well as ssh.
  • irssi needs the script loaded on startup & activated.
  • the irssi-in-screen session is started or re-attached with the following script:
    $ cat ~/bin/irssi_screen 
    # Start a new screen session with irssi or attach to an already running one.
    if screen -list | grep "\.irssi" > /dev/null
    then # running
            screen -x irssi
    else # not running
            screen -S irssi -t irssi irssi
    exit 0
  • for the URL stuff I use the script with:
    /set browse_command ~/.irssi/irssi_browser %u
  • irssi_browser is a little script for deciding which browser to use (I might run irssi on my client again one day & I'm syncing ~/.irssi/ between the client & the server):
    $ cat ~/.irssi/irssi_browser 
    if [ "$SSH_CLIENT" ]; then
            RHOST=$(echo $SSH_CLIENT | cut -f1 -d" ")
            ssh $RHOST DISPLAY=:0 sensible-browser "$URL" > /dev/null
            sensible-browser "$URL" >/dev/null &
    exit 0
    note: this assumes that a connection to the client is possible with ssh key authentication.

on the client

  • the following assumes that perl, xscreensaver, & some X stuff is installed, as well as a browser. & ssh of course.
  • to start the irssi-in-screen session via ssh in an xterm at X startup:
    $ grep irssi ~/.Xsession 
    (/usr/bin/xterm -name irssi -e /usr/bin/ssh server -t ~/bin/irssi_screen & ) && (~/bin/irssi_screen_xscreensaver &)
    note: this assumes that a connection to the server is possible with ssh key authentication.
  • irssi_screen_xscreensaver is a "daemon" that checks the xscreensaver status on the client and puts irssi in un/away mode on the server.
    $ cat ~/bin/irssi_screen_xscreensaver 
    my $blanked = 0;
    open (IN, "xscreensaver-command -watch |");
    while (<IN>) {
            if (m/^(BLANK|LOCK)/) {
                    if (!$blanked) {
                            system 'ssh server screen -p irssi -X stuff "/away\ -all\ not\ here\ ...^M"'
                            $blanked = 1;
            } elsif (m/^UNBLANK/) {
                    system 'ssh server screen -p irssi -X stuff "/away^M"';
                    $blanked = 0;
    note: the "^M" should be a literal Ctrl-M character, i.e. a CR (carriage return, "return", \13) & any spaces in the irssi -X stuff command need to be escaped with a \ (backslash).

gregoa, 2006-11-24, 2006-11-25, 2007-01-23, 2007-05-24, 2009-04-17

Creative Commons License
All material on this blog — unless stated otherwise — is © gregor herrmann, and is licensed under the Creative Commons Attribution-Share Alike 3.0 Austria License.