Bonus: slmenu, and some seriously wicked console wizardry

Whenever I use Musca, I learn to reappreciate dmenu.

You can keep your Unity, your Gnome3, even your gmrun or Kupfer. dmenu is a keypress and a half away and does only one teeny thing.

Too bad there’s not something like that for the console.

There is line completion, usually with the tab key. And some more advanced shells than bash do something similar to dmenu, I suppose, if you think about it.

Still, one keypress and a few letters to cue up the most popular programs on your computer … that might be useful, I suppose, if you think about it.

The suckless gang are rock-and-roll stars when it comes to featherweight software, so it should be no surprise that dmenu is in their stable.

Imitation is the sincerest form of flattery, and the author of slmenu acknowledges that a large proportion of its code was lifted straight from dmenu.

But slmenu, when prompted, looks … different?


What gives? Not much to work with there, K.Mandla! What’s it waiting for? Well, I can tell you.

Type in a couple of names of programs, then feed it the end-of-file key — CTRL+D.


Well, yes, that’s the general idea. Now you have a dmenu-esque line of applications that you can sift through either with tab completion or arrow keys.

But … that’s hardly helpful, you say. Who wants to type in the entire possible list of programs each time? That doesn’t just defeat the purpose, that’s the complete antithesis of what we’re chasing.

Fair enough. Suppose we had a list pre-made, with the most common software on the machine, in line-by-line format.


Would that do the trick? Now we just need to redirect that list back into slmenu, which is easier done than said.

slmenu < .progs.txt


Bingo. That’s exactly the behavior we’re after. So select a program and …


Crap. It just dumps the menu entry into stdout. It doesn’t execute it. Now how in the heck could we … wait:

eval `slmenu < .progs.txt`


Knock me over with a feather. It worked. 😯

But now … that is a heckuva line to have to type each time, just to get a single program started. You’re much better off with the original situation, you say.

True, but suppose we could create some kind of shortcut to that command … some kind of … alias. …

alias xe='eval `slmenu < .progs.txt`'


That should do the trick. I’ve been using xe because apparently nothing else starts with xe, and that’s sort of like “execute” in my mind. πŸ™„

Do that once and it’s good for your whole bash session. Drop it into your .bashrc and it’s there each time you log in.

Well, that’s nice, you say. But really, it’s still not very dmenu-ish. After all, you could just hotwire your entire .bashrc to cue your favorite software at a single character and an enter key, and skip the whole slmenu thing altogether. It’s just simpler to stick with the original, K.Mandla. 😐

All right. That stuffs it. The gloves are off. Here you go. Here’s the whole business, start to finish, cued up with one key press. Top this:

First we’re going to need a free key. Something that isn’t otherwise used by other software, and dedicate it to cueing that whole line, or at least the alias.

Lucky me, I have an extra key on my keyboard, painted with the logo of The Evil One.

The Microsoft key (or the Super_L key, or the Mod4 key, or whatever you want to call it) is tied to keycode 125 on my machine. I know this because showkey told me, when I tried it.

So now I need a copy of my console keymap, which is located in /usr/share/kbd/keymaps/i386/qwerty/, but is going to depend on your machine and architecture. Choose wisely.

cp /usr/share/kbd/keymaps/i386/qwerty/ ~/

Now we edit, adding these two lines at the end:

keycode 125 = F70
string F70 = "xe\n"

Save and close. On my Arch machine, only the root user can change the keymap, so:

sudo loadkeys

And there it is, with the -b option to force the display line to the end of the screen.

One. Key. Press.

Now you’re not allowed to complain about getting that into place or needing root access to assign a command to that keypress. And yes, I know it means any time your finger grazes that key you’ll get the slmenu display. Learn not to make that mistake.

And enjoy the one-key popup line-completion start menu you just installed for your text-only console system. Cue mad scientist laughter! 😈

As always, there may be easier ways or shorter aliases that will streamline this. And maybe there is a better way to put slmenu to use. Please let me know; I enjoy learning new tricks. πŸ™‚


19 thoughts on “Bonus: slmenu, and some seriously wicked console wizardry

  1. hhm0

    thanks for the awesome notes!

    by the way, you can just use the command “dumpkeys” instead of needing to go scavenge for the keymaps.

    also, you can make the new keymap have the customizations only for “loadkeys”.

    also “showkey” tells the scancode for a key.

    also customizing mappings is very useful for keyboards with lots of malfunctioning keys; just make other keys replace the broken ones when used with a “meta” key.

  2. Pingback: Links 19/3/2013: Linux 3.8 Approaching, Cyprus Banks News | Techrights

  3. Pingback: Bonus: slmenu in action | Inconsolation

  4. Pingback: dmpc: A client for a client for a daemon | Inconsolation

  5. Pingback: Bonus: What’s left of the Bs | Inconsolation

  6. Pingback: eval: Tells the shell what to do | Inconsolation

  7. Pingback: Bonus: 2013 in review | Inconsolation

  8. Pingback: pdmenu: The bane of geek showoffs | Inconsolation

  9. Pingback: sentaku: More menu-like options for the cli | Inconsolation

  10. Pingback: termsaver and terminal-screensaver: Peas in a pod | Inconsolation

  11. Pingback: t, ttytter, twidge and more: Text-only Twittermania | Inconsolation

  12. Pingback: percol: More menu-like options, plus searching and color | Inconsolation

  13. Pingback: fzf: More menu-like options, with fuzzy finding | Inconsolation

  14. Pingback: tmenu: Just one step away | Inconsolation

  15. Denis Chevalier

    Great post !

    But as dmenu isn’t enough for me, even on X, I had to make your trick work on xterm :
    Just as simple as
    $ echo ‘XTerm*translations: #override Menu:string(“xe\n”)\n’ >> ~/.Xdefaults && xrdb .Xdefaults

    Thanks !

  16. Pingback: fselect: Pulled from the brink | Inconsolation

  17. Pingback: iselect: A program’s got to know its limitations | Inconsolation

Comments are closed.