XMonad.Action.GridSelect spawnSelected with nice titles

There’s an awesome module available for XMonad called GridSelect. It contains very pretty window selectors and such. And one of it’s awesome functions is spawnSelected that aimed to build a grid menu with apps to run. Usage is pretty simple: spawnSelected conf ["xterm", "smplayer", "gvim"]. But what if you want to have nice titles rather than command names?

If you’ll take a look on that function source it zips given list with itself and feeds to gridlist function, which returns snd element of chosen tuple. That means you can easily write your own definitions that will allow to provide nice names for menu elements. So it will look something like this:

Let’s import module first:

import XMonad.Actions.GridSelect

Then we can define our version of spawnSelected like this:

spawnSelected' :: [(String, String)] -> X ()
spawnSelected' lst = gridselect conf lst >>= flip whenJust spawn
  where conf = defaultGSConfig

Now all you need to do is to add a hotkey to run your menu, something like this:

, ((modm, xK_r), spawnSelected'
  [ ("Mozilla Firefox", "firefox")
  , ("GVim",            "gvim")
  , ("MCabber",         "xterm -e detach -A /tmp/mcabber -z mcabber")
  , ("WeeChat",         "xterm -e detach -A /tmp/weechat -z weechat-curses")
  , ("Terminal",        "xterm")
comments powered by Disqus