Created
January 1, 2013 13:00
-
-
Save eagletmt/4427270 to your computer and use it in GitHub Desktop.
Prompt version of XMonad.Actions.WindowBringer.gotoMenu
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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