irssi in a screen session via ssh

objectives

  • 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 screen_away.pl script loaded on startup & activated.
  • the irssi-in-screen session is started or re-attached with the following script:
    $ cat ~/bin/irssi_screen 
    #!/bin/bash
    
    # 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
    fi
    
    exit 0
    $ 
    
  • for the URL stuff I use the script url.pl 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 
    #!/bin/sh
    
    URL=$1
    
    if [ "$SSH_CLIENT" ]; then
            RHOST=$(echo $SSH_CLIENT | cut -f1 -d" ")
            ssh $RHOST DISPLAY=:0 sensible-browser "$URL" > /dev/null
    else
            sensible-browser "$URL" >/dev/null &
    fi
    
    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 
    #!/usr/bin/perl
    
    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.