blog.lazkani.io/content/posts/weechat-ssh-and-notification.md

5.3 KiB

+++ title = "Weechat, SSH and Notification" author = ["Elia el Lazkani"] date = 2019-07-02T21:00:00+02:00 lastmod = 2021-06-28T00:01:44+02:00 tags = ["weechat", "notification", "ssh"] categories = ["irc"] draft = false +++

I have been on IRC for as long as I have been using Linux and that is a long time. Throughout the years, I have moved between terminal IRC clients. In this current iteration, I am using Weechat.

There are many ways one can use weechat and the one I chose is to run it in tmux on a cloud server. In other words, I have a Linux server running on one of the many cloud providers on which I have tmux and weechat installed and configured the way I like them. If you run a setup like mine, then you might face the same issue I have with IRC notifications.

Why?

Weechat can cause a terminal bell which will show on some terminals and window managers as a notification. But you only know that weechat pinged. Furthermore, if this is happening on a server that you are ssh'ing to, and with various shell configurations, this system might not even work. I wanted something more useful than that so I went on the hunt for the plugins available to see if any one of them could offer me a solution. I found many official plugins that did things in a similar fashion and each in a different and interesting way but none the way I want them to work.

Solution

After trying multiple solutions offered online which included various plugins, I decided to write my own. That's when weenotify was born. If you know my background then you know, already, that I am big on open source so weenotify was first released on Gitlab. After a few changes, requested by a weechat developer (FlashCode in #weechat on Freenode), weenotify became as an official weechat plugin.

Weenotify

Without getting into too many details, weenotify acts as both a weechat plugin and a server. The main function is to intercept weechat notifications and patch them through the system's notification system. In simple terms, if someone mentions your name, you will get a pop-up notification on your system with information about that. The script can be configured to work locally, if you run weechat on your own machine, or to open a socket and send the notification to weenotify running as a server. In the latter configuration, weenotify will display the notification on the system the server is running on.

Configuration

Let's look at the configuration to accomplish this... As mentioned in the beginning of the post, I run weechat in tmux on a server. So I ssh to the server before attaching tmux. The safest way to do this is to port forward over ssh and this can be done easily by ssh'ing using the following example.

 $ ssh -R 5431:localhost:5431 server.example.com

At this point, you should have port 5431 forwarded between the server and your machine.

Once the previous step is done, you can test if it works by trying to run the weenotify script in server mode on your machine using the following command.

 $ python weenotify.py -s
 Starting server...
 Server listening locally on port 5431...

The server is now running, you can test port forwarding from the server to make sure everything is working as expected.

 $ telnet localhost 5431
 Trying ::1...
 Connected to localhost.
 Escape character is '^]'.

If the connection is successful then you know that port forwarding is working as expected. You can close the connection by hitting Ctrl + ].

Now we are ready to install the plugin in weechat and configure it. In weechat, run the following command.

 /script search weenotify

At which point, you should be greeted with the buffer shown in the screenshot below.

{{< figure src="/ox-hugo/01-weechat-weenotify.png" caption="Figure 1: Weenotify" target="_blank" link="/ox-hugo/01-weechat-weenotify.png" >}}

You can install the plugin with Alt + i and make sure it autoloads with Alt + A. You can get more information about working with weechat scripts by reading the help menu. You can get the scripts help menu by running the following in weechat.

 /help script

The weenotify plugin is installed at this stage and only needs to be configured. The plugin has a list of values that can be configured. My configuration looks like the following.

 plugins.var.python.weenotify.enable  string  "on"
 plugins.var.python.weenotify.host    string  "localhost"
 plugins.var.python.weenotify.mode    string  "remote"
 plugins.var.python.weenotify.port    string  "5431"

Each one of those configuration options can be set as shown in the example below in weechat.

 /set plugins.var.python.weenotify.enable on

Make sure that the plugin enable value is on and that the mode is remote, if you're following this post and using ssh with port forwarding. Otherwise, If you want the plugin to work locally, make sure you set the mode to local.

If you followed this post so far, then whenever someone highlights you on weechat you should get a pop-up on your system notifying you about it.