Why is Ubuntu 22 always launching apps with gnome-terminal or xterm, even if an alternative is configured?

I want to switch to a new editor – LunarVim – and also to a new terminal that supports font ligatures – Kitty. Both installed globally on my system. I enabled it as the default terminal application using the following methods:

gsettings set org.gnome.desktop.default-applications.terminal exec /usr/local/bin/kitty

… to make it the default for the current user and

sudo update-alternatives --install /usr/bin/x-terminal-emulator x-terminal-emulator /usr/local/bin/kitty 50
sudo update-alternatives --config x-terminal-emulator

… to make it the default for x-terminal-emulator on the system. (tried it both with sudo and without)

When I press Ctrl + Alt + T it opens a Kitty terminal, so far so good.

I also added a .desktop file for LunarVim and added LunarVim as the default editor and default app for opening text files. I can confirm that this worked, I see the desktop entry in the launcher and text files open with LunarVim.

The problem is … LunarVim always opens in gnome-terminal. When I click on the icon in the app launcher, it opens in gnome-terminal. When I click on a txt file in the file explorer, it opens the gnome-terminal. I just want to understand why is this happening?

I even tried to remove gnome-terminal. I will always install xterm instead and then lunarvim will always be opened with xterm. When I try to remove xterm, it will automagically install gnome-terminal again …

It would be fantastic if anyone could enlighten me, I already literally spent hours for the simple task of installing a terminal in Ubuntu.

Just for completeness, here is the desktop file for lvim:

[Desktop Entry]
Name=LunarVim
GenericName=Text Editor
Comment=An IDE layer for Neovim with sane defaults. Completely free and community driven.
TryExec=lvim
Exec=lvim %F
Terminal=true
Type=Application
Keywords=Text;editor;
Icon=/opt/lunarvim/lvim/utils/desktop/64x64/lvim.svg
Categories=Utility;TextEditor;
StartupNotify=false
MimeType=text/english;text/plain;text/x-makefile;text/x-c++hdr;text/x-c++src;text/x-chdr;text/x-csrc;text/x-java;text/x-moc;text/x-pascal;text/x-tcl;text/x-tex;application/x-shellscript;text/x-c;text/x-c++;
Asked By: Chris

||

In Gnome Shell, there is no way of changing the terminal emulator to be used when a desktop launcher specifies Terminal=true. There is a way, though:

  1. Explicitly launch the terminal emulator (e.g. kitty) and have it load the terminal application, e.g., kitty lvim.

  2. Make sure lvim keeps having its own icon in the taskbar, separate from the icon of regular instances of kitty.

    a. have your terminal adopt a specific window class using a command line option, e.g., --class lunarvim in case of kitty terminal emulator.

    b. Add a statement StartupWMClass=lunarvim to the launcher.

Your .desktop launcher becomes:

[Desktop Entry]
Name=LunarVim
GenericName=Text Editor
Comment=An IDE layer for Neovim with sane defaults. Completely free and community driven.
TryExec=lvim
Exec=kitty --class lunarvim lvim %F
StartupWMClass=lunarvim
Terminal=false
Type=Application
Keywords=Text;editor;
Icon=/opt/lunarvim/lvim/utils/desktop/64x64/lvim.svg
Categories=Utility;TextEditor;
StartupNotify=false
MimeType=text/english;text/plain;text/x-makefile;text/x-c++hdr;text/x-c++src;text/x-chdr;text/x-csrc;text/x-java;text/x-moc;text/x-pascal;text/x-tcl;text/x-tex;application/x-shellscript;text/x-c;text/x-c++;
Answered By: vanadium