From 414b067f8e3f7daeefda0462934ec36d4f128310 Mon Sep 17 00:00:00 2001 From: Matt Turner Date: Wed, 8 Apr 2020 22:21:32 -0700 Subject: Initial import --- LICENSE | 25 +++++++++++++++++++++++++ README.md | 32 ++++++++++++++++++++++++++++++++ irssi.service | 26 ++++++++++++++++++++++++++ pid.pl | 26 ++++++++++++++++++++++++++ tmux-irssi.env | 2 ++ 5 files changed, 111 insertions(+) create mode 100644 LICENSE create mode 100644 README.md create mode 100644 irssi.service create mode 100644 pid.pl create mode 100644 tmux-irssi.env diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..122442e --- /dev/null +++ b/LICENSE @@ -0,0 +1,25 @@ +BSD 2-Clause License + +Copyright (c) 2020, Matt Turner +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..aa5cf27 --- /dev/null +++ b/README.md @@ -0,0 +1,32 @@ +# tmux+irssi as a systemd user-service + +A collection of hacks to run [irssi](https://irssi.org/) inside [tmux](https://tmux.github.io/) via a systemd user service. + +I hope by publishing this that someone can be inspired to find a way to do it without so many awful hacks (and let me know about it!). + +## Why + +I use [adv_windowlist.pl](https://github.com/irssi/scripts.irssi.org/blob/master/scripts/adv_windowlist.pl) which has great integration with tmux. + +I want irssi to start and stop cleanly on system reboot, which means starting up tmux. + +## What + +* `irssi.service`: systemd user service. Install to `/etc/systemd/user/` +* `tmux-irssi.env`: optional environment file. Install to `~/.config/` +* `pid.pl`: irssi script to write a pid file. Install to `~/.irssi/scripts/` (and symlink in `~/.irssi/scripts/autorun/`) + +## Installation + +After installing the files, just enable the service: + +```sh +$ systemctl --user daemon-reload +$ systemctl --user enable --now irssi +``` + +The you can connect to tmux with + +```sh +tmux -L irssi attach +``` diff --git a/irssi.service b/irssi.service new file mode 100644 index 0000000..58a9165 --- /dev/null +++ b/irssi.service @@ -0,0 +1,26 @@ +[Unit] +Description=irssi (in tmux) +Documentation=man:irssi(1) +Requires=nss-lookup.target +Wants=network-online.target +After=network-online.target nss-lookup.target + +[Service] +Type=forking +TimeoutSec=5 +WorkingDirectory=~ +Environment=WIDTH=80 HEIGHT=24 +EnvironmentFile=-%E/tmux-irssi.env +ExecStart=/bin/sh -c '/usr/bin/tmux -L %p -2 new-session -A -d -x ${WIDTH} -y ${HEIGHT} -s irssi /usr/bin/irssi' + +# Send CTRL+u to clear the input line before /quit +ExecStop=-/usr/bin/tmux -L %p send-keys -t irssi:0 C-u +ExecStop=-/usr/bin/tmux -L %p send-keys -t irssi:0 "/quit" Enter + +# Sending /quit to irssi is asynchronous, so wait for irssi to exit +# before killing the session in tmux +ExecStop=/bin/sh -c '/usr/bin/timeout 3 /usr/bin/tail --pid=$(/bin/cat %t/irssi.pid || echo 0) -f /dev/null' +ExecStop=-/usr/bin/tmux -L %p kill-session -t irssi + +[Install] +WantedBy=default.target diff --git a/pid.pl b/pid.pl new file mode 100644 index 0000000..adf261c --- /dev/null +++ b/pid.pl @@ -0,0 +1,26 @@ +use Irssi; +use strict; +use warnings; + +our $VERSION = "1.0"; +our %IRSSI = ( + authors => 'Matt Turner', + contact => 'mattst88@gmail.com', + name => 'pid', + description => 'Writes a pid file', + license => 'GNU GPLv2 or later', + url => 'https://mattst88.com/', +); + +my $pidfile = "$ENV{XDG_RUNTIME_DIR}/irssi.pid"; +open FH, ">", $pidfile or die "Error writing '$pidfile': $!\n"; +print FH $$; +close FH; + +sub remove_pidfile { + unlink $pidfile; +} + +Irssi::command_bind('quit', 'remove_pidfile'); + +# vim:set ts=2 sw=2 expandtab: diff --git a/tmux-irssi.env b/tmux-irssi.env new file mode 100644 index 0000000..bfa348c --- /dev/null +++ b/tmux-irssi.env @@ -0,0 +1,2 @@ +WIDTH=211 +HEIGHT=51 -- cgit v1.2.3