Topic: Recursive dmenu
Hey,
so dmenu is pretty cool but it does have a limitation compared to other launchers such as Enso, Gnome Do, Quicksilver, etc. etc. You can only do one thing with one hot key.
For example if I bind the usual dmenu script (the one for launching a program from your path) to my Caps Lock key then all I can do from my Caps Lock key is launch a program. I can write dmenu scripts for all kinds of things: selecting a file from my homedir and opening it, doing a google search, looking something up in a dictionary, anything I want really. But I would need a different key bind for each dmenu script.
In Enso (and other launchers) it is different. You summon Enso, select your command (e.g. Open, Define, Google), then select your input to that command (a file or program to open, a word to look up, a term to search for). There's an extra step in there that allows you to run many different Enso commands from a single hot key.
So I wanted to do this with dmenu. My idea is:
1. Create a ~/dmenu_scripts directory where you keep all your different dmenu scripts for doing different things, as many of them as you want.
2. Outside of this directory (e.g. in your normal ~/scripts dir) create this dmenu-bind.sh script:
#!/bin/sh
~/dmenu_scripts/`ls ~/dmenu_scripts | dmenu -nb '#a5b474' -sb '#444444' -nf '#eeeeee' -sf '#a5b474' -fn '-*-*-*-*-*-*-20-*-*-*-*-*-*-*'`What that does is list all of your scripts from ~/dmenu_scripts in dmenu and execute the one that you select. Bind this script to a key (I like to use Caps Lock).
So lets say you have dmenu scripts 'run', 'open', 'edit', 'define' and 'google' to do various things. You press Caps Lock (or whatever your keybind is) and dmenu pops up listing "run open edit define google" and anything else you have in dmenu scripts. You select 'run'. dmenu immediately pops up again this time listing all the programs on your path. This is the ~/dmenu_scripts/run script now. You select a program and it gets executed. We are using one dmenu script to select and then execute another dmenu script. Get it?
Here's my attempt at a few useful scripts for ~/dmenu_scripts, but no doubt these could be better because I'm not much of a shell scripter. Post your own!
Define something with gnome-dictionary (filename 'define'):
#!/bin/sh
gnome-dictionary --look-up `dmenu -nb '#a5b474' -sb '#444444' -nf '#eeeeee' -sf '#a5b474' -fn '-*-*-*-*-*-*-20-*-*-*-*-*-*-*'`Open a file from your homedir with gedit (filename 'gedit'):
#!/bin/sh
gedit `ls | dmenu -nb '#a5b474' -sb '#444444' -nf '#eeeeee' -sf '#a5b474' -fn '-*-*-*-*-*-*-20-*-*-*-*-*-*-*'`Google something with firefox (filename 'google'):
#!/bin/sh
firefox -new-window http://www.google.co.uk/search?q="`dmenu -nb '#a5b474' -sb '#444444' -nf '#eeeeee' -sf '#a5b474' -fn '-*-*-*-*-*-*-20-*-*-*-*-*-*-*'`"Open something (file, folder, URL) from your homedir with gnome-open (filename 'open'):
#!/bin/sh
gnome-open `ls | dmenu -nb '#a5b474' -sb '#444444' -nf '#eeeeee' -sf '#a5b474' -fn '-*-*-*-*-*-*-20-*-*-*-*-*-*-*'`Run a command from your path (filename 'run'):
#!/bin/sh
`dmenu_path | dmenu -nb '#a5b474' -sb '#444444' -nf '#eeeeee' -sf '#a5b474' -fn '-*-*-*-*-*-*-20-*-*-*-*-*-*-*'` && eval "exec $exe"I also have a slightly more complex one called 'markdown' that lets you select a file from your homedir, runs the file through the program markdown, and shows you the result in your web browser.