Dynamic Options - bakkeby/dmenu GitHub Wiki

Dynamic options is a relatively niche feature that has limited use cases.

The general idea is that for every character you type into dmenu the input is passed to a dedicated command which can return a list of new menu options to present to the user.

A basic example of this is to pass ls as a dynamic option.

$ dmenu -dy ls

This demonstrates that if the input matches one of the immediate subdirectories then the dmenu options will change to show items in said subdirectory.

Now let us move on to a more practical example having a file fruits.sh which on empty input gives the menu of Apples, Pears and Bananas.

#!/bin/bash

case $1 in
	Apples) # menu 1
		echo -e "Pink Lady\nFuji\nGala"
		;;

	Pears) # menu 2
		echo -e "Conference\nBartlett\nComice"
		;;

	Bananas) # menu 3
		echo -e "Cavendish\nPisang Raja\nBurro"
		;;

	*)
		if [ "$1" = "" ]; then
			echo -e "Apples\nPears\nBananas"
		fi
		;;
esac

Here is how to run this script. Note that the script needs to have execute permissions to run.

$ dmenu -dy ./fruits.sh

fruits1.jpg

Now start typing in "Pears".

fruits2.jpg

When the last "s" is entered the menu options dynamically change to Conference, Bartlett and Comice as the script outputs that when the input is "Pears".

fruits3.jpg

Selecting the Bartlett option and pressing enter will result in "Bartlett" being the dmenu output.

$ dmenu -dy ./fruits.sh
Bartlett

In practice one would likely want to execute dmenu with dynamic options from a script that takes an action based on the option selected, if not embedded into the dynamic options script iself.

One advantage this approach has is that the dmenu window itself does not need to be teared down and created again between menus.

Note that previous selections will be cleared if the menu is dynamically updated.

Note that although case insensitive matching can be used in dmenu the example shell script does not take that into account (i.e. entering "pears" would not result in the menu changing). If this is important then either force dmenu to do case sensitive matching, or make sure that the shell script supports case insensitive matching.

Configuration wise it is possible to set dedicated dynamic script, but one should only ever want to do this if the dmenu binary is to be hardcoded to always run such a script.

This feature originates from the dynamicoptions patch for dmenu.

Back to Features.

⚠️ **GitHub.com Fallback** ⚠️