98 lines
5.6 KiB
Org Mode
98 lines
5.6 KiB
Org Mode
#+BEGIN_COMMENT
|
|
.. title: Weechat, SSH and Notification
|
|
.. date: 2019-01-01
|
|
.. updated: 2019-07-02
|
|
.. status: published
|
|
.. tags: irc, ssh, weechat, notification,
|
|
.. category: irc
|
|
.. slug: weechat-ssh-and-notification
|
|
.. authors: Elia el Lazkani
|
|
.. description: A way to patch weechat notifications through your system's libnotify over ssh.
|
|
.. type: text
|
|
#+END_COMMENT
|
|
|
|
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 [[https://weechat.org/][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.
|
|
|
|
{{{TEASER_END}}}
|
|
|
|
* 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 [[https://gitlab.com/elazkani/weenotify][Gitlab]]. After a few changes, requested by a weechat developer (*FlashCode* in *#weechat* on [[https://freenode.net/][Freenode]]), /weenotify/ became as an [[https://weechat.org/scripts/source/weenotify.py.html/][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.
|
|
|
|
#+BEGIN_EXAMPLE
|
|
$ ssh -R 5431:localhost:5431 server.example.com
|
|
#+END_EXAMPLE
|
|
|
|
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.
|
|
|
|
#+BEGIN_EXAMPLE
|
|
$ python weenotify.py -s
|
|
Starting server...
|
|
Server listening locally on port 5431...
|
|
#+END_EXAMPLE
|
|
|
|
The server is now running, you can test port forwarding from the server to make sure everything is working as expected.
|
|
|
|
#+BEGIN_EXAMPLE
|
|
$ telnet localhost 5431
|
|
Trying ::1...
|
|
Connected to localhost.
|
|
Escape character is '^]'.
|
|
#+END_EXAMPLE
|
|
|
|
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.
|
|
|
|
#+BEGIN_EXAMPLE
|
|
/script search weenotify
|
|
#+END_EXAMPLE
|
|
|
|
At which point, you should be greeted with the buffer shown in the screenshot below.
|
|
|
|
#+BEGIN_EXPORT html
|
|
<a class="reference" href="/images/weechat-ssh-and-notification/01-weechat-weenotify.png" alt="weenotify" align="center">
|
|
<img src="/images/weechat-ssh-and-notification/01-weechat-weenotify.thumbnail.png">
|
|
#+END_EXPORT
|
|
#+BEGIN_EXPORT html
|
|
</a>
|
|
#+END_EXPORT
|
|
|
|
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.
|
|
|
|
#+BEGIN_EXAMPLE
|
|
/help script
|
|
#+END_EXAMPLE
|
|
|
|
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.
|
|
|
|
#+BEGIN_EXAMPLE
|
|
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"
|
|
#+END_EXAMPLE
|
|
|
|
Each one of those configuration options can be set as shown in the example below in weechat.
|
|
|
|
#+BEGIN_EXAMPLE
|
|
/set plugins.var.python.weenotify.enable on
|
|
#+END_EXAMPLE
|
|
|
|
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.
|