From 796d9cb6ba58700c1d98582e5cd5125c78048d58 Mon Sep 17 00:00:00 2001 From: gwern0 Date: Mon, 8 Oct 2007 00:02:36 +0200 Subject: ShellPrompt.hs: add getShellCompl to export list getShellCompl is useful for writing prompts in Config.hs or even full standalone prompts; and personally, if a small utility function like 'split' can be exported, how much more so something useful like getShellCompl? darcs-hash:20071007220236-f7719-7b0a4c794bdbce3b19a785bbe01f734e002114c2.gz --- ShellPrompt.hs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/ShellPrompt.hs b/ShellPrompt.hs index 077fd8c..ecd8d56 100644 --- a/ShellPrompt.hs +++ b/ShellPrompt.hs @@ -3,7 +3,7 @@ -- Module : XMonadContrib.ShellPrompt -- Copyright : (C) 2007 Andrea Rossato -- License : BSD3 --- +-- -- Maintainer : andrea.rossato@unibz.it -- Stability : unstable -- Portability : unportable @@ -16,6 +16,7 @@ module XMonadContrib.ShellPrompt ( -- * Usage -- $usage shellPrompt + , getShellCompl , split ) where @@ -55,7 +56,7 @@ shellPrompt :: XPConfig -> X () shellPrompt c = mkXPrompt Shell c getShellCompl spawn getShellCompl :: String -> IO [String] -getShellCompl s +getShellCompl s | s /= "" && last s /= ' ' = do f <- fmap lines $ runProcessWithInput "/bin/bash" [] ("compgen -A file " ++ s ++ "\n") c <- commandCompletionFunction s @@ -69,7 +70,7 @@ commandCompletionFunction str | otherwise = do p <- getEnv "PATH" `catch` const (return []) let ds = split ':' p - fp d f = d ++ "/" ++ f + fp d f = d ++ "/" ++ f es <- forM ds $ \d -> do exists <- doesDirectoryExist d if exists @@ -88,7 +89,7 @@ split :: Eq a => a -> [a] -> [[a]] split _ [] = [] split e l = f : split e (rest ls) - where + where (f,ls) = span (/=e) l rest s | s == [] = [] | otherwise = tail s -- cgit v1.2.3