Skip to content

Instantly share code, notes, and snippets.

@eagletmt
Created January 1, 2013 13:00
Show Gist options
  • Save eagletmt/4427270 to your computer and use it in GitHub Desktop.
Save eagletmt/4427270 to your computer and use it in GitHub Desktop.
Prompt version of XMonad.Actions.WindowBringer.gotoMenu
module XMonad.Prompt.Goto (gotoPrompt, GotoPrompt) where
import XMonad.Prompt
import XMonad.Actions.WindowBringer (windowMap)
import XMonad.Core (X)
import XMonad.Operations (windows)
import qualified XMonad.StackSet as W
import Data.List
import qualified Data.Map as M
data GotoPrompt = GotoPrompt
instance XPrompt GotoPrompt where
showXPrompt _ = "Window: "
nextCompletion _ input compls = compls !! nextIdx
where
nextIdx =
case input `elemIndex` compls of
Just idx
| idx >= length compls - 1 -> 0
| otherwise -> idx + 1
Nothing -> 0
gotoPrompt :: XPConfig -> X ()
gotoPrompt xpconfig = do
wm <- windowMap
mkXPrompt GotoPrompt xpconfig (mkComplFun (M.keys wm)) $ \selection ->
case M.lookup selection wm of
Just win -> windows $ W.focusWindow win
Nothing -> return ()
where
mkComplFun :: [String] -> String -> IO [String]
mkComplFun candidates input = return $ filter (input `isInfixOf`) candidates
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment