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

114 lines
5.4 KiB
Markdown

---
Title: Rofi's keyboard shortcut for passwordstore on Wayland
Date: 2023-07-10 12:00
Author: Fabrice
Category: Tips
Tags: pass, rofi, tessen
Slug: tessen-shortcut
Header_Cover: ../images/covers/keyboards.jpg
Summary: How to configure keyboard inputs for rofi menu on wayland for pass
Lang: en
---
I recently switched from [xorg](https://x.org/) to
[wayland](https://wayland.freedesktop.org/) with [sway](https://swaywm.org/).
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](https://github.com/debauchee/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](https://github.com/carnager/rofi-pass), a
wrapper around [pass]({filename}../software/pass.md) using
[rofi](https://github.com/davatorium/rofi) as a user interface.
While using it to type passwords outside software that can integrate
[`pass`](https://passwordstore.org), 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](https://git.epheme.re/fmouhart/my-pkgs/src/branch/master/rofi-pass/rofi-pass.patch).
Now, looking more closely into the wayland tooling ecosystem, I found [tessen]
[tessen](https://github.com/ayushnix/tessen), that supports multiple dmenu-like interfaces, including `rofi` but also
a wayland-native menu system called [fuzzel](https://codeberg.org/dnkl/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](https://en.wikipedia.org/wiki/Approximate_string_matching) algorithm was
too different from the one used by [fzf](https://github.com/junegunn/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](https://en.wikipedia.org/wiki/Time-based_one-time_password) 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](https://en.wikipedia.org/wiki/Exit_status) 10 on some password
description, which is nice because some configuration options in _rofi_ just do
that:
[`kb-custom-<n>`](https://github.com/davatorium/rofi/blob/next/doc/rofi-keys.5.markdown#kb-custom-1)
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](https://www.reddit.com/r/linuxquestions/comments/tw8x5j/comment/i3edajm/)
that explained it to me.
Putting everything togethere, it leads to the following configuration file
`$HOME/.config/rofi/tessen.rasi`:
```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`:
```sh
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](https://github.com/ayushnix/tessen/blob/master/config#L23) on my computer.
I'll look into it [someday](https://en.wikipedia.org/wiki/Procrastination) to
have a clean configuration files setup… maybe.