1

After some digging, I managed to find that to get the name of the user's preferred terminal emulator, as set in the 'Default Applications' section of KDE5's settings, one can run this command:

kreadconfig5 --file kdeglobals --group General --key TerminalApplication

In my case (running Manjaro with KDE Plasma 5), this returns the string 'alacritty'. Thus, wrapping this in $(...) and typing the resulting command inside a terminal launches the user's preferred terminal emulator (I have tested that this work).

Yet, when I create a custom keyboard shortcut for KDE to run this command with Meta+Return, nothing happens. I also tried putting exec in front of it in case it was necessary, but it changed nothing. If i just set up the shortcut to run the command alacritty (which is what is returned by the first command I mentioned), then it works, but of course I want to be able to run whatever is the user's preferred terminal, not a specific one.

Can anyone explain to me why it is not working? Am I doing something wrong?

2
  • Well @fra-san, sh -c '$(...)' indeed worked! I'm not completely familiar with shell scripting or with the shell flags, so I assume I was missing the -c option and the single quotes. For that reason I'm hesitating whether to answer the post myself with that solution or not, because I don't fully understand why it worked or what I was missing...
    – Thomas.M
    Commented Jun 25, 2021 at 7:30
  • I turned my comment into an answer. I'm deleting my comments here.
    – fra-san
    Commented Jun 25, 2021 at 9:16

1 Answer 1

1

The construct $(...) (command substitution) is part of the POSIX shell command language and requires a shell in order to interpret it. As far as I can tell, application launchers included in desktop environments are not required to be able to interpret the shell command language; to err on the safe side, I would assume they can only execute a file and pass it a list of arguments.

You should be able define a keyboard shortcut that invokes something like:

sh -c '"$(kreadconfig5 ...)"'

The command substitution is wrapped in double quotes to ensure it will not fail if the file path produced by the substituted command contains whitespace characters.
For completeness, note that this will still fail if the name of the executable file ends in one or more newline characters (extremely unlikely, of course).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .