{"id":1381,"date":"2021-12-11T22:34:31","date_gmt":"2021-12-11T17:04:31","guid":{"rendered":"https:\/\/smarttech101.com\/?p=1381"},"modified":"2023-03-25T00:50:08","modified_gmt":"2023-03-24T19:20:08","slug":"dmenu-what-it-is-and-how-i-use-it","status":"publish","type":"post","link":"https:\/\/smarttech101.com\/dmenu-what-it-is-and-how-i-use-it\/","title":{"rendered":"Dmenu – What It Is and How I Use It"},"content":{"rendered":"\n
Dmenu enables us to create something like right-click menu in Windows OS. You can use it in your shell scripts<\/a>. In these scripts, you just need to supply your list of menus to dmenu, and then you can choose any one of them. Now, based on the chosen menu, you can take any action.<\/p>\n\n\n\n And it also comes with additional benefits:<\/p>\n\n\n\n Modularity<\/strong> brings many advantages. You can combine it with many modular packages like sxiv (an image viewer), systemctl<\/strong> suspend\/poweroff\/reboot, etc., and create your own package! This is one of the features I like about Linux. You don’t have to stay dependent on big corporates. They first create an application\/software which we want. At the start, they sell it for free or at a low cost to lure us in. And when we get dependent on these applications, they keep increasing the price. On top of that, you will have to wait for these big corporates to bring additional features you like. For example, you need to buy a whole new copy of Windows 11 for a feature called Tiling Windows available in Linux for decades. <\/p>\n\n\n\n In this article, you will learn about installation, available features, patches, modern-day useful examples, and how dmenu can replace many packages.<\/p>\n\n\n\n Debian\/Ubuntu\/Raspbian<\/strong>\/Kali Linux<\/strong><\/p>\n\n\n\n Archlinux:<\/strong><\/p>\n\n\n\n Alpine<\/strong><\/p>\n\n\n\n Fedora<\/strong><\/p>\n\n\n\n Now that we have installed the dmenu on our system, we will familiarize ourselves with some terms in the dmenu.<\/p>\n\n\n\n Dmenu reads a list of newline-separated items from standard input. For the stdin, use either Example Syntax: <\/strong><\/p>\n\n\n\n Output:<\/strong><\/p>\n\n\n\n At the top left corner, you will get a search bar. Right next to it, you will get all of your menu items. In the above example, I have three menu items – poweroff, reboot, and suspend. You can choose one of the items using either arrow keys or by typing in the Search Bar. Then hit Enter key. The chosen item will be printed out on the terminal. You can take further action on this choice using another pipe<\/strong>. To continue with the above example, if I add xargs systemctl<\/strong>:<\/p>\n\n\n\n Here, the xargs just takes your choice and adds it next to the systemctl, and then executes it. So, if you choose the ‘suspend’ menu, xargs will execute a command ‘systemctl suspend’. And then your system will be suspended. <\/p>\n\n\n\n So in just one line, we created a power-menu which, like any desktop OS, can power off, reboot and suspend your system.<\/p>\n\n\n\n Using options, you can set dmenu’s fonts, colors, vertical\/horizontal placement, and top\/bottom placement, etc.<\/p>\n\n\n\n As I told you earlier, in the dmenu you can type out in the search bar to select your menu. By default, it is case-sensitive. So, for example, if you type ‘test’ in the search bar, it will match only those menus which have ‘test’ in them. If you want to include ‘Test’ as well, use case-insensitive matching. For this, you need to use <\/strong>the Example:<\/strong><\/p>\n\n\n\n By default, the dmenu places itself on top of the screen. You can use the By default, dmenu places menus in a horizontal bar. To place them vertically, use Here, in the above command, As you have been seeing, the default size of the font is very small. You need to increase the font size. At the same time, you can also change the font. For this purpose we use the As you might have guessed, 18 is font size and Ubuntu is the name of the font. <\/p>\n\n\n\n Note: To find font names, you can use The default color is black and blue which is a little off-putting. You can change it using color flags \n
Table of Contents<\/h2>\n\n\n\n
\n
\n
1. Installation<\/h2>\n\n\n\n
~$ sudo apt-get install suckless-tools<\/code><\/pre>\n\n\n\n
~$ sudo pacman -S dmenu<\/code><\/pre>\n\n\n\n
~$ sudo apk add dmenu<\/code><\/pre>\n\n\n\n
~$ sudo dnf install dmenu<\/code><\/pre>\n\n\n\n
2. Getting Familar with Dmenu<\/h2>\n\n\n\n
pipe (|)<\/strong> or <<\/strong><\/code>. <\/strong><\/p>\n\n\n\n
~$ echo -e \"poweroff\\nreboot\\nsuspend\" | dmenu <\/code><\/pre>\n\n\n\n
~$ echo -e \"poweroff\\nreboot\\nsuspend\" | dmenu | xargs systemctl<\/code><\/pre>\n\n\n\n
3. Options Available<\/h2>\n\n\n\n
3.1. Case Insensitive Matching in the Search Bar<\/h3>\n\n\n\n
-i<\/code> <\/strong>flag.<\/p>\n\n\n\n
~$ echo -e \"poweroff\\nreboot\\nsuspend\" | dmenu -i<\/code><\/pre>\n\n\n\n
3.2. Bottom Placement of Dmenu<\/h3>\n\n\n\n
-b<\/code><\/strong> flag to put it at the bottom.<\/p>\n\n\n\n
3.3. Vertical Placement of Menus <\/h3>\n\n\n\n
-l<\/code> <\/strong>flag:<\/strong><\/p>\n\n\n\n
~$ ps -e | dmenu -l 10<\/code><\/pre>\n\n\n\n
ps -e<\/code> lists the processes running on your computer. And the
-l 10<\/code> flag places the dmenu vertically with a maximum of 10 items in it. This way you will not lose sight of your existing window.<\/p>\n\n\n\n
3.4. Font Configuration in Dmenu<\/h3>\n\n\n\n
-fn<\/code><\/strong> flag:<\/p>\n\n\n\n
~$ echo -e \"poweroff\\nreboot\\nsuspend\" | dmenu -fn \"Ubuntu-18\"<\/code><\/pre>\n\n\n\n
fc-list<\/code><\/strong> command.<\/p>\n\n\n\n
3.5. Dmenu No More “Black and Blue”<\/h3>\n\n\n\n
-nb, -nf, -sb, and -sf<\/code><\/strong>.<\/p>\n\n\n\n