Dmenu: The fast and minimalist launcher for Linux

Introduction

In the Linux ecosystem, speed and efficiency are fundamental values for many users, especially those who spend much of their time in the terminal. Dmenu is presented as a light and extremely flexible solution that allows you to launch applications, run commands or select elements from a list with just a few keyboard strokes. Its minimalist design does not sacrifice power; on the contrary, as it is based on standard input and standard output, it is integrated without friction with any desktop environment or window manager.

What is Dmenu?

Dmenu is a dynamic menu for X that reads a list of elements from the standard input and shows those that match the pattern written by the user. Originally created as part of the suckless toolkit, its philosophy follows the principle of «do one thing and do it right». It does not depend on heavy libraries, but on Xlib and a simple configuration using X resources or header files. This makes it an ideal option for systems where low resource consumption and deep customization capacity are valued.

Installation

The Dmenu installation is simple in most Linux distributions. In Debian or Ubuntu based systems, just run:

sudo apt update && sudo apt install dmenu

In Arch Linux and its derivatives, the package is in the official repositories:

sudo pacman -S dmenu

For Fedora, the command is:

sudo dnf install dmenu

If you prefer to compile from the source code to get the latest version or apply custom patches, the process is typical of suckless projects:

git clone https://git.suckless.org/dmenu
cd dmenu
make clean
make
sudo make install

After installation, the commanddmenuit will be available in the PATH and can be invoked from any terminal or by keyboard shortcuts set up in the window manager.

Basic use

The simplest operation of Dmenu consists of tubing a list of options and letting the user filter and select one of them. For example, to launch an application present in$PATH, you can use the scriptdmenu_runwhich is included:

dmenu_run

This command generates a list of all executables found on the routes defined in$PATH, shows the menu and, by pressing Enter on an option, runs it. Another common way is to use Dmenu to select a file from a directory:

ls | dmenu

After choosing the file, your name is returned to the standard output, which allows you to chain it with other commands, such as opening it with an editor:

ls | dmenu | xargs -r vim

The flexibility of reading from stdin and writing to stdout makes Dmenu a highly reusable component in scripts and pipes.

Personalization

Although Dmenu looks nice by default, its true strength lies in the ability to adapt it to the tastes and needs of each user. The customization is mainly done through the X resources, which can be defined in the file~/.Xresourcesor~/.Xdefaults. Some of the most common properties are:

  • dmenu.font: -misc-fixed-medium-r-normal--12-120-75-75-c-60-iso10646-1
  • dmenu.normbgcolor: #222222
  • dmenu.normfgcolor: #eeeeee
  • dmenu.selbgcolor: #005577
  • dmenu.selfgcolor: #ffffff

After modifying the resource file, it is necessary to recharge them withxrdb -merge ~/.Xresourcesso that the changes have an effect on the next execution of Dmenu. In addition, if compiled from the source code, it is possible to adjust constant directly in the fileconfig.hbefore compiling, which allows to change the top of the menu, maximum width, sensitivity behavior to capital / lower case and other low level details.

Integration with scripts

One of the most powerful advantages of Dmenu is its ease to be called from shell scripts, which allows you to create custom launchers, context menus or quick management tools. For example, a simple script to connect to SSH servers by a previously defined list could be:

#!/bin/sh
HOSTS="servidor1.example.com servidor2.example.com servidor3.example.com"
CHOICE=$(echo "$HOSTS" | tr ' ' '\n' | dmenu -p "SSH:")
[ -n "$CHOICE" ] && ssh "$CHOICE"

Similarly, you can create a menu to mount units, change audio profiles or even run system maintenance tasks. The key is to generate the list of options by any command (likefind, greporsystemctl list-units) and pass that list to Dmenu by a pipe.

Advanced trout

The most experienced users can take Dmenu beyond its basic use by combining it with other suckless ecosystem tools or with their own extensions. Some popular tricks include:

  • Command history:Usedmenu_run -i -l 5to show a limited number of lines and make insensitive match to capital / lower case, while saving the history in a file and reading each time to offer the most used options.
  • Integration with i3:In the i3 window manager, you can link a key toexec_always --no-startup-id dmenu_runto launch applications quickly without leaving the keyboard.
  • File selection with preview:Combine Dmenu withfzforvimto get a preview of the content before deciding to open it.
  • Dynamic menus based on context:Detect the current directory or status of a service and adapt the list of options shown by Dmenu in real time.

These techniques show that, although Dmenu is simple in its concept, its text-flow-based architecture makes it a versatile piece to build highly personalized and efficient workflows.

Conclusion

Dmenu represents the essence of Unix philosophy: doing a specific task in an excellent way and allowing other tools to enhance it by composition. Its low resource consumption, ease of installation and adaptability make it essential for both novice users looking for a fast launcher and advanced administrators who want to create contextuais menus and automation scripts. If you have not yet tested it, incorporating Dmenu into your daily workflow can transform the way it interacts with your Linux system, saving time and reducing the dependence on heavy graphical interfaces.

This work is under aCreative Commons License Attribution 4.0 International for Francesc Roig francesc @ vivaldi.net.

EnglishenEnglishEnglish