aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgwern0 <gwern0@gmail.com>2008-06-07 09:12:25 +0200
committergwern0 <gwern0@gmail.com>2008-06-07 09:12:25 +0200
commite66e7b49e14e98fd2d6415d57ba9bcac9a727ea2 (patch)
treec6ab971273b01f4037e7d9f5a5869f11a16f1cb7
parentf169b3b613e5355e689fcf36dda63457d0d4f02d (diff)
downloadXMonadContrib-e66e7b49e14e98fd2d6415d57ba9bcac9a727ea2.tar.gz
XMonadContrib-e66e7b49e14e98fd2d6415d57ba9bcac9a727ea2.tar.xz
XMonadContrib-e66e7b49e14e98fd2d6415d57ba9bcac9a727ea2.zip
Prompt.hs: +a historyCompletion function for use in XPrompts
darcs-hash:20080607071225-f7719-4e0154662c45e9a3fc4d575e4eda0963598d8248.gz
-rw-r--r--XMonad/Prompt.hs13
1 files changed, 13 insertions, 0 deletions
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