blog/content/tips/tessen.md
2023-07-10 11:58:56 +02:00

5.4 KiB

Title Date Author Category Tags Slug Header_Cover Summary Lang
Rofi's keyboard shortcut for passwordstore on Wayland 2023-07-10 12:00 Fabrice Tips pass, rofi, tessen tessen-shortcut ../images/covers/keyboards.jpg How to configure keyboard inputs for rofi menu on wayland for pass en

I recently switched from xorg to wayland with sway.

One of the several roadblocks to this change lies in that some tools that heavily rely on graphical environment are not fully compatible with wayland, such as barrier, a keyboard, mouse and clipboard sharing system between multiple computers.

However, the most annoying hindrance was that alternative tools that have been built with wayland in mind actually alter my habits too much for my comfort. One of such tools I used is rofi-pass, a wrapper around pass using rofi as a user interface.

While using it to type passwords outside software that can integrate pass, I developed some habits with the default keyboard shortcuts of rofi-pass such as Alt+c to copy the password (for a short time) or Alt+Return to evaluate the autotype field in a password file.

At first, we can notice that rofi-pass is not much more than a bash script which gather its data from pass/gopass, the X11 clipboard manager and xdotools to automate some actions. As such, one solution can be to directly modify the bash script, even if it's not very elegant.

Now, looking more closely into the wayland tooling ecosystem, I found [tessen] tessen, that supports multiple dmenu-like interfaces, including rofi but also a wayland-native menu system called fuzzel. Tessen thus gather the output of these programs to enact the corresponding request using wl-copy/wl-paste for the clipboard and wtype for typing.

I first tried to use fuzzel, however, their fuzzy search algorithm was too different from the one used by fzf, which is integrated in many of the everyday tools I used (such as completing commands in my shell), and some usual shortcuts such as Ctrl+u to clear my search don't seem to work natively.

I thus decided to use rofi which was doing a tremendous job so far, even if it launched through xwayland and is not considered pure enough by some people. However the rofi-pass-specific shortcuts don't seem to work out of the box. Fortunately (?), the man tessen whispers in my ears that it is possible:

If the dmenu program of your choice supports custom keybindings with exit codes greater than or equal to 10, tessen can execute custom operations on a selected file in the first menu. At the very least, fuzzel(1), bemenu(1), and rofi(1) support this feature.

In particular, it integrates some way to directly type and copy OTP codes for two factor authentication, which is a feature that I manually patched in my rofi-pass file to have “Alt+o” typing an OTP code.

We now have everything we need to put it in action. First, we have to find a way to tell rofi to send exit code 10 on some password description, which is nice because some configuration options in rofi just do that: kb-custom-<n> allows associating some keyboard inputs to the “9+n” exit code. kb-custom-1 then sends the signal 10 and kb-custom-9 sends 20. It seems obvious now, but it was not written clearly in the documentation, and I first used kb-custom-10 hoping it will send signal 10… I don't have to tell you that it didn't work as intended. Luckily I found a reddit comment that explained it to me.

Putting everything togethere, it leads to the following configuration file $HOME/.config/rofi/tessen.rasi:

configuration {
	/* Tessen */
	kb-custom-1: "Alt+Return"; /* autotype */
	kb-custom-2: "Alt+u";      /* autotype user */
	kb-custom-3: "Alt+p";      /* autotype password */
	kb-custom-5: "Alt+t";      /* copy user */
	kb-custom-6: "Alt+c";      /* copy password */
	kb-custom-8: "Alt+o";      /* autotype otp */
}
@import "config"               /* import default config */

I initially tried to add it to rofi general-purpose configuration file, $XDG_CONFIG_HOME/rofi/config.rasi, but it conflicted with rofimoji shortcuts which didn't hesitate to explain the situation.

The final step is to integrate this to tessen, which can be done in the configuration file $XDG_CONFIG_HOME/tessen/config:

dmenu_backend="rofi"
rofi_config_file="$HOME/.config/rofi/tessen.rasi"

For some unknown reason that I didn't look deep inside, $XDG_CONFIG_HOME does not work unlike what is hinted in the tessen example configuration file on my computer. I'll look into it someday to have a clean configuration files setup… maybe.