2

The first thing I've been taught to do when I use Debian or Ubuntu is to create a shortcut (in my case Ctr+Alt+T) to open a terminal. To do this I create a new keyboard shortcut (in the X system's options>keyboard) with the code x-terminal-emulator. This seems straight forward enough as a bash command: typing this into the terminal also produces a terminal window.

Currently I'm using Debian 9.5 (Stretch) and I'm trying to define some shortcuts for a new external keyboard. However, when I try to create shortcuts for other commands I can use from the terminal (such as firefox or echo "$"), the shortcut does not work. I can't seem to find good documentation about what kind of command the create shortcut does take, but it does not quite seem to accept bash commands.

slava
  • 3,887

1 Answers1

2

The first thing I've been taught to do when I use Debian or Ubuntu is to create a shortcut (in my case Ctr+Alt+T) to open a terminal. To do this I create a new keyboard shortcut (in the X system's options>keyboard) with the code x-terminal-emulator

There's two types of shortcuts. Some of them are managed by desktop environment - things like Ctr+Alt+T. Different desktop environments manage different set of shortcuts. Such desktops as GNOME, Unity, LXDE, MATE, etc - they have code built-in for that and you can't really change those shortcuts without recompiling the desktop environment code. Desktops like Openbox, Blackbox - they don't manage these shortcuts. What you've been taught should be considered within context of your desktop environment. You should not need to declare shortcut for x-terminal-emulator for the desktops like GNOME and others I've mentioned earlier, because they already manage that.

However, when I try to create shortcuts for other commands I can use from the terminal (such as firefox or echo "$"), the shortcut does not work.

Custom shortcuts - what you declare yourself - operate on executables, that is you have to specify valid file existing on disk, such as /bin/bash or at least a command that exists in one of directories listed under $PATH variable. The desktop environment will run execve() syscall to start that app when you press the shortcut. This is also the reason why echo $? doesn't work - there is no shell to understand what $? means. The shell variables only have meaning inside shell. So what do you do? Tell the shortcut to start the shell ! Usually this is done via bash -c 'echo $?' for short commands or use a script with appropriate #! line at the top of the script. So key thing to remember shortcuts don't run shell commands, they run executables. To give a practical example where bash -c '...' is used, see How to create a shortcut that executes an xdotool command to simulate a key press?

AS for why firefox didn't work for you, firefox may be checking for existing open windows or there is another error. Consider doing bash -c 'firefox > 2>&1 foxlogfile.txt' to find out the cause of the issue or any errors that may appear.

I can't seem to find good documentation about what kind of command the create shortcut does take, but it does not quite seem to accept bash commands.

The short answer - there's no such documentation, really. So long as you remember that shortcuts use executable files instead of shell commands, that's all you really need. And of course you need to know what is the method of declaring shortcuts on your desktop - Openbox method is different from GNOME for example.

P.S: Actually, there is a third type of shortcuts but they're not related to desktop environment, i.e. they are not GUI shortcuts. bash reads ~/.inputrc file, where you can declare certain commands to be executed for particular key combination. However, this is outside the scope of this question and is a different topic. See this for an example.

P.S.2: Desktops based on GNOME, such as Unity, utilize GSettings and DConf database to apply particular settings to each user of desktop. As such, shortcuts under those environment can be controlled and set via command-line, but the same concept applies - they have to be either executables or something the desktop environment recognizes because it's in desktop environment's code. See this article about one of my scritps to disable Super key under Unity and Jacob Vlijm's answer for setting shortcuts via terminal ( remember this applies to GNOME-based ones only).

See also

slava
  • 3,887
Sergiy Kolodyazhnyy
  • 105,154
  • 20
  • 279
  • 497
  • Tiny thing: Ctrl + Alt + T isn't hard coded, it is in /org/gnome/settings-daemon/plugins/media-keys/terminal and can be changed. – Jacob Vlijm Dec 19 '18 at 15:14