From e66e7b49e14e98fd2d6415d57ba9bcac9a727ea2 Mon Sep 17 00:00:00 2001 From: gwern0 Date: Sat, 7 Jun 2008 09:12:25 +0200 Subject: Prompt.hs: +a historyCompletion function for use in XPrompts darcs-hash:20080607071225-f7719-4e0154662c45e9a3fc4d575e4eda0963598d8248.gz --- XMonad/Prompt.hs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/XMonad/Prompt.hs b/XMonad/Prompt.hs index cbcf7a3..c8664b4 100644 --- a/XMonad/Prompt.hs +++ b/XMonad/Prompt.hs @@ -43,6 +43,7 @@ module XMonad.Prompt , uniqSort , decodeInput , encodeOutput + , historyCompletion ) where import XMonad hiding (config, io) @@ -779,3 +780,15 @@ breakAtSpace s -- | Sort a list and remove duplicates. uniqSort :: Ord a => [a] -> [a] uniqSort = toList . fromList + +-- | 'historyCompletion' provides a canned completion function much like +-- getShellCompl; you pass it to mkXPrompt, and it will make completions work +-- from the query history stored in ~/.xmonad/history. +historyCompletion :: ComplFunction +historyCompletion = \x -> liftM (filter $ isInfixOf x) readHistoryIO + +-- We need to define this locally because there is no function with the type "XP a -> IO a", and +-- 'getHistory' is uselessly of the type "XP [String]". +readHistoryIO :: IO [String] +readHistoryIO = do (hist,_) <- readHistory + return $ map command_history hist \ No newline at end of file -- cgit v1.2.3