aboutsummaryrefslogtreecommitdiffstats
path: root/ShellPrompt.hs
diff options
context:
space:
mode:
authorAndrea Rossato <andrea.rossato@unibz.it>2007-10-05 13:22:50 +0200
committerAndrea Rossato <andrea.rossato@unibz.it>2007-10-05 13:22:50 +0200
commit98ce4744cdb4d34f4437f74e932913240b223028 (patch)
tree89d50be07697c8e485ac1c4e68adc5782871db05 /ShellPrompt.hs
parent3b5757bc2b6019b95221f5558f5e17bdd2416ad4 (diff)
downloadXMonadContrib-98ce4744cdb4d34f4437f74e932913240b223028.tar.gz
XMonadContrib-98ce4744cdb4d34f4437f74e932913240b223028.tar.xz
XMonadContrib-98ce4744cdb4d34f4437f74e932913240b223028.zip
ShellPrompt: removed readline dependency and added escape character support
darcs-hash:20071005112250-32816-1a6ded5818357ce989dd7cadf6eb0d0fc9503ef5.gz
Diffstat (limited to 'ShellPrompt.hs')
-rw-r--r--ShellPrompt.hs42
1 files changed, 24 insertions, 18 deletions
diff --git a/ShellPrompt.hs b/ShellPrompt.hs
index 6b06df6..d68d7cf 100644
--- a/ShellPrompt.hs
+++ b/ShellPrompt.hs
@@ -22,33 +22,26 @@ module XMonadContrib.ShellPrompt (
import XMonad
import XMonadContrib.XPrompt
+import XMonadContrib.Dmenu
import Control.Monad
import Data.List
-import System.Console.Readline
+import System.Directory
+import System.IO
import System.Environment
-- $usage
--
--- 1. In xmonad.cabal change:
---
--- > build-depends: base>=2.0, X11>=1.2.1, X11-extras>=0.2, mtl>=1.0, unix>=1.0
---
--- to
---
--- > build-depends: base>=2.0, X11>=1.2.1, X11-extras>=0.2, mtl>=1.0, unix>=1.0, readline >= 1.0
---
--- 2. In Config.hs add:
+-- 1. In Config.hs add:
--
-- > import XMonadContrib.XPrompt
-- > import XMonadContrib.ShellPrompt
--
--- 3. In your keybindings add something like:
+-- 2. In your keybindings add something like:
--
-- > , ((modMask .|. controlMask, xK_x), shellPrompt defaultXPConfig)
--
--- %cabalbuilddep readline>=1.0
-- %import XMonadContrib.XPrompt
-- %import XMonadContrib.ShellPrompt
-- %keybind , ((modMask .|. controlMask, xK_x), shellPrompt defaultXPConfig)
@@ -65,21 +58,25 @@ shellPrompt c = mkXPrompt Shell c getShellCompl spawn
getShellCompl :: String -> IO [String]
getShellCompl s
| s /= "" && last s /= ' ' = do
- fl <- filenameCompletionFunction s
+ f <- fmap lines $ runProcessWithInput "/bin/bash" [] ("compgen -A file " ++ s ++ "\n")
c <- commandCompletionFunction s
- return $ sort . nub $ fl ++ c
+ hPutStrLn stdout s
+ return $ map escape . sort . nub $ f ++ c
| otherwise = return []
commandCompletionFunction :: String -> IO [String]
commandCompletionFunction str
| '/' `elem` str = return []
- | otherwise = do
+ | otherwise = do
p <- getEnv "PATH"
cl p
where
- cl = liftM (nub . rmPath . concat) . mapM fCF . map addToPath . split ':'
- addToPath = flip (++) ("/" ++ str)
- fCF = filenameCompletionFunction
+ cl = liftM (nub . rmPath . concat) . mapM cmpl . split ':'
+ cmpl s = filter (isPrefixOf str) `fmap` getFileNames s
+
+getFileNames :: FilePath -> IO [FilePath]
+getFileNames fp =
+ getDirectoryContents fp `catch` \_ -> return []
rmPath :: [String] -> [String]
rmPath s =
@@ -94,3 +91,12 @@ split e l =
rest s | s == [] = []
| otherwise = tail s
+escape :: String -> String
+escape [] = ""
+escape (' ':xs) = "\\ " ++ escape xs
+escape (x:xs)
+ | isSpecialChar x = '\\' : x : escape xs
+ | otherwise = x : escape xs
+
+isSpecialChar :: Char -> Bool
+isSpecialChar = flip elem "\\@\"'#?$*()[]{};"