There are few ways to get what you need:
- Use one of the available tools like Kumfer, GMRun, Launchy, etc;
- Adapt
dmenu
to suite your needs.
Adapting dmenu
When you call dmenu_run
, it's actually calling dmenu_path
and piping it to dmenu
itself. Which means you can pretty much pipe anything to dmenu
. If you get an empty string (and different exit code) selection was canceled. Otherwise, you get a selected command.
You can write a script that would get information you would like to be presented with dmenu
pipe it and wait for selection. This is a bit more complex than using one of the other launchers but it provides a lot of flexibility and further more I don't think there's anything lighter than dmenu
.
For example, I have this script written:
#!/usr/bin/env python
import os
from subprocess import Popen, PIPE, STDOUT
# dmenu constants
DMENU_CACHE = os.path.expanduser('~/.dmenu_cache')
DMENU_COMMAND = [
'dmenu',
'-p', 'command:',
'-nb', '#151515',
'-nf', '#888888',
'-l', '10',
'-fn', '-misc-fixed-medium-*-normal-*-14-*-*-*-*-*-*-*'
]
# our custom commands
commands = {
'nautilus': 'nautilus --no-desktop'
}
# check if local cache exists
if not os.path.exists(DMENU_CACHE):
os.system('dmenu_path > /dev/null')
# load command cache and combine with our commands
with open(DMENU_CACHE, 'r') as raw_file:
system_commands = raw_file.read()
output = commands.keys()
output.sort()
# create a process
process = Popen(DMENU_COMMAND, stdout=PIPE, stdin=PIPE, stderr=STDOUT)
selection = process.communicate(input='{0}\n{1}'.format('\n'.join(output), system_commands))[0]
# get command based on selection and execute it
if selection.strip() != '':
command = commands[selection] if commands.has_key(selection) else selection
os.system(command)
It uses dmenu
cache generated by dmenu_path
, but prioritizes items I've placed in commands
dictionary. Also allows me to add custom commands I need.