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

97 lines
5.3 KiB
Markdown

+++
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](https://weechat.org/).
<!--more-->
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? {#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 {#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](https://gitlab.com/elazkani/weenotify). After a few changes, requested by a weechat developer (**FlashCode** in **#weechat** on [Freenode](https://freenode.net/)), _weenotify_ became as an [official weechat plugin](https://weechat.org/scripts/source/weenotify.py.html/).
## Weenotify {#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 {#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.
```text
$ 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.
```text
$ 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.
```text
$ 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.
```text
/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.
```text
/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.
```text
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.
```text
/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.