Search code examples
waylandvifmkitty

Issue with previewing images in vifm on wayland with kitty on arch linux


I'm trying to set up image previewing in vifm on Wayland with kitty on Arch Linux. However, when I try to preview an image, I get the error:

Error: Failed to open controlling terminal with error: open /dev/tty: no such device or address

vifmrc:

fileviewer *.bmp,*.jpg,*.jpeg,*.png,*.xpm,*.webp
        \ kitty +kitten icat --transfer-mode=file --place=%pwx%ph@%pxx%py %c
        \ %pc
        \ kitty +kitten icat --transfer-mode=file --place=%pwx%ph@%pxx%py --clear
  • vifm version: 0.12.1
  • arch: 6.2.11-arch1-1
  • display server: wayland
  • terminal: kitty 0.27.1

I've already tried googling (and chatgpt and phind ofc) the error message, but I couldn't find a solution that worked for me. Can anyone suggest a fix for this error?

Thanks in advance for your help!


Solution

  • The answer to your question is in this GitHub issue: kitty v0.27+ won't work Vifm v0.12.1. The :fileviewer command in the question also lacks %N which is necessary since Vifm v0.12 and here is its version for kitty v0.27+:

    fileviewer *.bmp,*.jpg,*.jpeg,*.png,*.xpm,*.webp
        \ kitten icat --silent --transfer-mode=file --place=%pwx%ph@%pxx%py %c >/dev/tty </dev/tty %N
        \ %pc
        \ kitten icat --clear --silent >/dev/tty </dev/tty %N
    

    Why >/dev/tty? Because despite requiring the terminal to be present it doesn't write to it anymore, kitty v0.27 writes to stdout.

    Why </dev/tty? Otherwise kitty v0.27 refuses to process --place because it suddently thinks that you passed in 2 files if stdin isn't connected to /dev/tty.


    History of the question:

    1. Vifm v0.12 started running background jobs (including preview commands) detached from a terminal, so that they couldn't mess up its state or Vifm's TUI by printing something on the screen.
    2. Turned out that image preview of Kitty doesn't work without talking to the terminal (seems to be artificial limitation).
    3. Vifm v0.12.1 added %N macro to work around this and the issue was resolved for a while.
    4. Looks like Kitty v0.27 started taking process group into account while %N in Vifm created a new one for the preview command.
    5. Vifm v0.13 changed %N to keep Vifm's process group.

    You'll have wait for Vifm v0.13 to be available in Arch Linux or build Vifm yourself.