Score:0

Keyboard shortcut to launch dmenu

kr flag

I've got a snippets file in my home directory with two simple commands

ls
whoami

Running the following terminal command utilizes dmenu to allow me to select a line in my snippets file and pipe the output to whatever application I have in focus (usually my terminal):

xdotool type $(grep -v '^#' ~/snippets | dmenu -i -l 50 | cut -d' ' -f1)

I want to bind Super+Ins to run that command above, and have attempted via Settings > Keyboard Shortcuts > + and entering the following for the command to issue:

gnome-terminal -e "xdotool type $(grep -v '^#' ~/snippets | dmenu -i -l 50 | cut -d' ' -f1)"

When I go ahead and use this new keyboard shortcut Super+Ins I get the following output

(grep-v^#~/snippets|dmenu-i-l50|cut-d -f1)

instead of the expected dmenu selection. What am I doing wrong? My OS is Ubuntu 22.04 under GNOME running X11.

Score:1
cn flag

Command substitution will not work from the shortcut definition. It must be run in bash for it to work. Instead, move your xdotool command in a small script and have the shortcut definition point to that script instead.

kr flag
I tried your suggestion, added `sleep 0.3` to the command, and used the command directly as a shortcut key, but the output from `Super+Ins` is still `grep-v^#~/snippets|dmenu-i-l50|cut-d -f1)` instead of the expected dmenu snippet list. Were you able to get my concept working, or was this just your initial thoughts on how to fix the issue?
vanadium avatar
cn flag
I see. It is the command substitution that does not work from within a shortcut key - command substitution works in scripts and on the bash shell. Thus, xdotool just literally types the string you provided. Changed the answer.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.