[xmonad] fuzzy/partial matching on prompts?

Adam Vogt vogt.adam at gmail.com
Sun Oct 17 18:01:17 EDT 2010

* On Sunday, October 17 2010, Eric Abrahamsen wrote:

>I haven't been able to find anything in the docs on this… All I want is
>for certain prompts to use fuzzy or partial matching: the XMondad.Topic
>switchTopic function was what prompted this, but I see plenty of cases
>(dzen) where it would be very nice. But particularly for switching
>topic/workspaces: it's a pain having to type out whole names, even when
>the list has already been narrowed to a single member…
>There's probably some configuration option I'm missing—does anyone have
>any pointers?

An edit distance for the definition of fuzzy might help:

Which you could used in something like:

import Data.List
import Text.EditDistance
import XMonad; import XMonad.Prompt; import XMonad.Prompt.Shell

data FuzzySpawn = FuzzySpawn deriving (Read, Show)
instance XPrompt FuzzySpawn where showXPrompt _ = "Spawn: "

fuzzySpawn = do
    cmds <- io getCommands
    let compl s
          | null s = []
          | otherwise = let weight c = levenshteinDistance defaultEditCosts s c
            in map snd $ take 20 $ sort $ map (\c -> (weight c,c)) cmds
    mkXPrompt FuzzySpawn defaultXPConfig (return . compl) spawn

XMonad.Prompt is a bit inconsistent (XPrompt class vs. XPConfig data,
where all configurations could be data AFAICT), so it takes a bit of
work to understand, but it isn't that bad.


More information about the xmonad mailing list