Skip to main content

Hello ! This is my blog powered by Known. I post articles and links about coding, FOSS, but not only, in French (mostly) or English (if I did not find anything related before).

phyks.me

github.com/phyks

phyks@phyks.me

 

Moving from URxvt to st

2 min read

I have been using URxvt terminal for a while, but was suffering many issues with it recently. In particular, I had a weird locale issue, leading to unicode encoding errors whenever I copy accentuated characters using primary keyboard, some weird issues due to urxvt-tabbed and it just blew up when I tried to get new unicode characters right in it (such as smileys).

A friend told me about st which may be quite daunting at first, especially since all the configuration is made statically in a C header file, but it is working incredibly well, and just doing the job fine.

I have a mirror repo with my own configuration in case you want to have a look at it. This reproduces most of my URxvt user experience, except from two things:

  1. I don't have any tabs in st. But this is not a real issue and I'd rather depend on another program to handle tabs, such as tmux or even i3.
  2. I don't have clickable URLs as I used to have in URxvt. But once again, after a few weeks without this feature, I prefer selecting and copy/pasting URLs rather than clicking on them. This way, I don't open links unintentionally.

I was relying on a hack to get local notifications for my Weechat running through SSH + screen, using an extended escape sequence, and if you are also using it this commit will implement this behavior in st.

#

 
 

Improved back and forth between workspaces

2 min read

i3 has a feature to enable going back and forth between workspaces. Once enabled, if you are on workspace 1 and switch to workspace 2 and then just press mod+2 again to switch to workspace 2, you will go back to workspace 1.

However, this feature is quite limited as it does not remember more than one previous workspace. For example, say you are on workspace 1, switch to workspace 2 and then to workspace 3. Then, typing mod+3 will send you back to workspace 2 as expected. But then, typing mod+2 will send you back to workspace 3 whereas one may have expected it to switch to workspace 1 (as does Weechat with buffers switch for instance).

This can be solved by wrapping around the workspace switching in the i3 config. I wrote this small script to handle it.

Basically, you have to start the script when you start i3 by putting

exec_always --no-startup-id "python PATH_TO_/workspace_back_and_forth_enhanced.py"

in your .i3/config file.

Then, you can replace your bindsym commands to switch workspaces, calling the same script:

bindsym $mod+agrave exec "echo 10 | socat - UNIX-CONNECT:$XDG_RUNTIME_DIR/i3/i3-back-and-forth-enhanced.sock" (Replace $XDG_RUNTIME_DIR by /tmp if this environment variable is not defined on your system.)

This script does maintain a queue of 20 previously seen workspaces (so you can go back 20 workspaces ago in your history). This can be increased by editing the WORKSPACES_STACK = deque(maxlen=20) line according to your needs.

Hope this helps! :)

 

workspace_back_and_forth stack : i3wm

Improved version of moving back and forth between workspaces in i3wm. Inspired by Weechat buffers.

 

Les énigmes du réseau Free Mobile

3 min read

C'est très étrange… Là où je suis, la connexion SSH est toujours utilisable (avec un lag important rendant très insupportable toute édition de fichiers, mais Weechat over SSH est utilisable), mais le débit sur le port 80 est très fluctuant. Quelques fois les pages se chargent très rapidement, quelques fois il n'y a pas moyen de charger une seule page, même après 10 minutes d'attente et trois tentatives (indépendamment du domaine, donc pas un problème de peering a priori).

Par contre, passer sa connexion web dans un tunnel SOCKS améliore grandement les choses. Et de façon générale, j'ai déjà remarqué ça à plusieurs reprises sur des connexion lentes (Free Mobile, mais aussi certains hotspots etc.). À 18h, la connexion est toujours inutilisable, mais ça rend la connexion internet utilisable le reste du temps.

Je précise que je suis dans une zone censée être couverte en H+ (je le cherche encore le fabuleux débit promis par toutes les dernières technos, quand en HSDPA, j'ai tout juste un débit d'EDGE) et encore loin de mon plafond mensuel de 3Go (et de toutes façons, le même comportement est observé avec des clients utilisant peu la 3G)… qu'est-ce que ça va être après ?

Du coup, Free bride-t-il le port 80 ? Ou l'antenne est-elle surchargée (par des gens qui font du web, donc du port 80) ? Ça m'étonne quand même cette différence significative de débit selon les ports utilisés (à titre de comparaison, je ne pouvais pas mettre à jour mon système avec yaourt tout à l'heure, débit trop faible, mais un téléchargement de quelques mégaoctets dans mon Firefox sur proxy SOCKS se faisait en un temps « raisonnable » et je peux récupérer mes emails par POP/IMAP sans problème).

Bref, c'est pas la première fois que je remarque ça, et heureusement j'ai la possibilité de faire un tunnel SOCKS sur mon kimsufi, mais comment fait Madame Michu ?! Et surtout… pourquoi ce comportement si étrange sur le port 80 ?

P.S. : J'ai pensé au début que c'était Orange qui bridait le débit des abonnés Free sur ses antennes, me rappelant d'histoires similaires au lancement, et confirmé par un portable chez Sosh qui tourne sans problème. Mais il semblerait que je sois sur une antenne Free…

 

Local notifications for Weechat and UrXVT

3 min read

After moving from irssi to weechat, I decided to look for a way to have local notifications for IRC messages. The problem is that I run weechat through a screen on my server, which I access thanks to SSH. Thus, I need to find a way to allow weechat to communicate to my local terminal and send notifications.

I found many solutions on the web which were using a local server or a pipe file. But these aren't fitted to my needs, as they need an external program running on my machine, which I don't want. I was quite sure there could be a way to do it, with nothing more than my terminal emulator and weechat plugins, and I finally found it. My solution is based on karma-lab's one [French].

The idea is to use the Bell signal which corresponds to the ASCII escape sequence 7 to raise attention (beep signal). The following steps work fine with UrXVT and weechat in a screen session. It may be possible to adapt this to other terminal emulators or terminal multiplexers (such as tmux) but I don't use them and can't help you much with it. We will define our own escape sequence, that will be interpreted by an UrXVT plugin and will spawn a notification with the IRC message.

First of all, you will have to modify your ~/.Xdefaults or your ~/.Xresources to tell UrXVT to listen for bell signals. In order to do so, just add the following line:

URxvt*urgentOnBell: true

Then, reload it:

$ xrdb -load ~/.Xdefaults

Your UrXVT terminal now listens to bell signals. But we'd like them to spawn real local notifications. For this, I used libnotify, which is built-in in gnome. The main idea is to enhance our bell signal with a more complete escape sequence to include a message to display (using the so-called osc sequences). Thus, the sequence sent to UrXVT will look like [ESC]777;notify;TITRE;MESSAGEBELL]. Just add the following plugin (written by Karma-lab[French] and slightly modified by me to enhance security) to your UrXVT and you are ready to go. So, you should put this plugin in /usr/lib/urxvt/perl/notify.

To test that everything worked correctly, you can use the following command:

$ echo -ne "\033]777;notify;Moi;Hello World\007\007"

which should spawn an "Hello World" notification on your desktop.

Finally, if the previous example is working fine, let's integrate it to Weechat. We'll need another plugin for weechat, to make him write this escape sequence when needed to send notifications. This plugin is also from karma-labs, but as my weechat is running in a screen session, I had to tweak it a bit. I improved security of the plugin as well, to prevent any unauthorized code execution. Concerning screen, it is “consuming” the escape sequences for itself, and you have to tweak it a bit to make it pass through screen. The python script to load in your Weechat can be found here.

Have fun with IRC and your brand new notifications !

,

 

Hilight window in weechat

4 min read

I recently moved from Irssi+Screen to Weechat+Screen (and I'm planning to look at weechat interfaces in the future, to have a local irc client connecting to my server and avoid any latency while typing on low speed internet connection). My first step was to get almost the same setup as irssi. I'm very pleased with what I achieved, and weechat is definitely an excellent irc client, although it lacks a bit of usable documentation sometimes…

To get something like my old irssi, I had to install some extensions, including :

  • text_effects.lua to have some inline text decoration such as *bold* to display bold in bold
  • buffers.pl to have a list of opened buffers
  • iset.pl to set configuration options easily
  • screen_away.py (which is very efficient !) to auto away when I detach my screen session

I extensively used this link and the other articles on weechat on this website, which is a reference in my opinion, to get a working base weechat configuration.

But, one point that wasn't documented very well, is the use of a hilight window without dedicating a buffer to it. Dedicating a buffer to the hilight window means having an opened buffer in the main window, which is useless. You always select it accidentally by typing the wrong number for another buffer, and it's hidous in your buffer list (even though you can hide it from there). I don't know if this could be done in irssi, but in weechat, you can set highmon to use a bar instead of a buffer to display the "hilight window" and this is what we'll see in the following. I will assume you start with highmon plugin installed and configured, with a hilight window such as the one from Pascal Poitras.

So, first step is to tell highmon to use a bar for output instead of the standard buffer :

/set plugins.var.perl.highmon.output bar

Highmon should have created a bar automatically, to put the messages in. Check weechat.bar.highmon.* options to make sure it did. Next, type :

/set plugins.var.perl.highmon.bar_lines 250

to set the number of lines to be stored in your freshly created bar.

Then, you can edit all the preferences for the bar (size, size_max, position, priority, hide etc.) as for a standard bar, using weechat.bar.highmon.* options. Note that priority is important if you have to bars having the same position. For instance, if two bars are positioned at the top, the priority property will determine which one is above the other one.

One last point is that we'd like to have a title for the new hilight bar (which by default doesn't have any title). The hack is to use another plugin, text_item.py to display a bar with some text. To make a title "[Hilight Monitor]", just run (after having installed text_item.py):

/set plugins.var.python.text_item.hilight_monitor_title_text all "[Hilight Monitor]"
/bar add highmon_title top 1 0 hilight_monitor_title_text

And play with the position, priority and colors for the newly created bar to have a nice setup :)

One last important thing is that, contrary to the buffer solution, you won't be able to clean easily the hilight window and to scroll in it. But, I found two aliases on (ty @silverd for the aliases) that you can bind to any key if you want:

/alias clear_highmon /mute /set plugins.var.perl.highmon.bar_lines -1;/mute /set weechat.bar.highmon.items "";/mute /set weechat.bar.highmon.items "highmon";/mute /set plugins.var.perl.highmon.bar_lines 250
/alias scroll_highmon_down /bar scroll highmon * y+100%
/alias scroll_highmon_up /bar scroll highmon * y-100%

You can now clear the hilight window with /clear_highmon and scroll in it with the other aliases. So, I think you are good to go for a (quite) perfect weechat setup :)

Update:

  • You can define your own keyboard shortcut in the following way:
    /key bind KEY /scroll_highmon
    where KEY is some key or combination of key (for instance meta-meta2-A or whatever you want). You can do the same for /clear_highmon and /scroll_highmon_up.
  • By default, the highmon bar won't autoscroll. To enable autoscroll, you should set plugins.var.perl.highmon.bar_scrolldown to on.