mirror of
https://github.com/xmonad/xmonad-contrib.git
synced 2025-08-06 06:51:55 -07:00
Maybe? What Maybe? (rollback earlier dmenu change)
This commit is contained in:
@@ -102,9 +102,7 @@ runCommand :: [(String, X ())] -> X ()
|
|||||||
runCommand cl = do
|
runCommand cl = do
|
||||||
let m = commandMap cl
|
let m = commandMap cl
|
||||||
choice <- dmenu (M.keys m)
|
choice <- dmenu (M.keys m)
|
||||||
case choice of
|
fromMaybe (return ()) (M.lookup choice m)
|
||||||
Just selection -> fromMaybe (return ()) (M.lookup selection m)
|
|
||||||
Nothing -> return ()
|
|
||||||
|
|
||||||
runCommand' :: String -> X ()
|
runCommand' :: String -> X ()
|
||||||
runCommand' c = do
|
runCommand' c = do
|
||||||
|
@@ -18,8 +18,6 @@ module XMonadContrib.DirectoryPrompt (
|
|||||||
directoryPrompt
|
directoryPrompt
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Data.Maybe(fromMaybe)
|
|
||||||
|
|
||||||
import XMonad
|
import XMonad
|
||||||
import XMonadContrib.XPrompt
|
import XMonadContrib.XPrompt
|
||||||
import XMonadContrib.Dmenu ( runProcessWithInput )
|
import XMonadContrib.Dmenu ( runProcessWithInput )
|
||||||
@@ -36,7 +34,7 @@ directoryPrompt :: XPConfig -> String -> (String -> X ()) -> X ()
|
|||||||
directoryPrompt c prom job = mkXPrompt (Dir prom) c getDirCompl job
|
directoryPrompt c prom job = mkXPrompt (Dir prom) c getDirCompl job
|
||||||
|
|
||||||
getDirCompl :: String -> IO [String]
|
getDirCompl :: String -> IO [String]
|
||||||
getDirCompl s = (filter notboring . lines . fromMaybe "") `fmap`
|
getDirCompl s = (filter notboring . lines) `fmap`
|
||||||
runProcessWithInput "/bin/bash" [] ("compgen -A directory " ++ s ++ "\n")
|
runProcessWithInput "/bin/bash" [] ("compgen -A directory " ++ s ++ "\n")
|
||||||
|
|
||||||
notboring :: String -> Bool
|
notboring :: String -> Bool
|
||||||
|
18
Dmenu.hs
18
Dmenu.hs
@@ -22,7 +22,6 @@ module XMonadContrib.Dmenu (
|
|||||||
import XMonad
|
import XMonad
|
||||||
import qualified StackSet as W
|
import qualified StackSet as W
|
||||||
import qualified Data.Map as M
|
import qualified Data.Map as M
|
||||||
import System.Exit
|
|
||||||
import System.Process
|
import System.Process
|
||||||
import System.IO
|
import System.IO
|
||||||
import Control.Monad.State
|
import Control.Monad.State
|
||||||
@@ -36,7 +35,7 @@ import Control.Monad.State
|
|||||||
|
|
||||||
-- | Returns Just output if the command succeeded, and Nothing if it didn't.
|
-- | Returns Just output if the command succeeded, and Nothing if it didn't.
|
||||||
-- This corresponds to dmenu's notion of exit code 1 for a cancelled invocation.
|
-- This corresponds to dmenu's notion of exit code 1 for a cancelled invocation.
|
||||||
runProcessWithInput :: FilePath -> [String] -> String -> IO (Maybe String)
|
runProcessWithInput :: FilePath -> [String] -> String -> IO String
|
||||||
runProcessWithInput cmd args input = do
|
runProcessWithInput cmd args input = do
|
||||||
(pin, pout, perr, ph) <- runInteractiveProcess cmd args Nothing Nothing
|
(pin, pout, perr, ph) <- runInteractiveProcess cmd args Nothing Nothing
|
||||||
hPutStr pin input
|
hPutStr pin input
|
||||||
@@ -45,21 +44,20 @@ runProcessWithInput cmd args input = do
|
|||||||
when (output==output) $ return ()
|
when (output==output) $ return ()
|
||||||
hClose pout
|
hClose pout
|
||||||
hClose perr
|
hClose perr
|
||||||
exitCode <- waitForProcess ph
|
waitForProcess ph
|
||||||
case exitCode of
|
return output
|
||||||
ExitSuccess -> return (Just output)
|
|
||||||
ExitFailure _ -> return Nothing
|
|
||||||
|
|
||||||
-- | Starts dmenu on the current screen. Requires this patch to dmenu:
|
-- | Starts dmenu on the current screen. Requires this patch to dmenu:
|
||||||
-- <http://www.jcreigh.com/dmenu/dmenu-3.2-xinerama.patch>
|
-- <http://www.jcreigh.com/dmenu/dmenu-3.2-xinerama.patch>
|
||||||
dmenuXinerama :: [String] -> X (Maybe String)
|
dmenuXinerama :: [String] -> X String
|
||||||
dmenuXinerama opts = do
|
dmenuXinerama opts = do
|
||||||
curscreen <- (fromIntegral . W.screen . W.current) `liftM` gets windowset :: X Int
|
curscreen <- (fromIntegral . W.screen . W.current) `liftM` gets windowset :: X Int
|
||||||
io $ runProcessWithInput "dmenu" ["-xs", show (curscreen+1)] (unlines opts)
|
io $ runProcessWithInput "dmenu" ["-xs", show (curscreen+1)] (unlines opts)
|
||||||
|
|
||||||
dmenu :: [String] -> X (Maybe String)
|
dmenu :: [String] -> X String
|
||||||
dmenu opts = io $ runProcessWithInput "dmenu" [] (unlines opts)
|
dmenu opts = io $ runProcessWithInput "dmenu" [] (unlines opts)
|
||||||
|
|
||||||
dmenuMap :: M.Map String a -> X (Maybe a)
|
dmenuMap :: M.Map String a -> X (Maybe a)
|
||||||
dmenuMap selectionMap =
|
dmenuMap selectionMap = do
|
||||||
dmenu (M.keys selectionMap) >>= return . maybe Nothing (flip M.lookup selectionMap)
|
selection <- dmenu (M.keys selectionMap)
|
||||||
|
return $ M.lookup selection selectionMap
|
||||||
|
@@ -25,7 +25,6 @@ import XMonadContrib.Dmenu
|
|||||||
|
|
||||||
import Control.Monad
|
import Control.Monad
|
||||||
import Data.List
|
import Data.List
|
||||||
import Data.Maybe
|
|
||||||
import System.Directory
|
import System.Directory
|
||||||
import System.IO
|
import System.IO
|
||||||
import System.Environment
|
import System.Environment
|
||||||
@@ -58,7 +57,7 @@ shellPrompt c = mkXPrompt Shell c getShellCompl spawn
|
|||||||
getShellCompl :: String -> IO [String]
|
getShellCompl :: String -> IO [String]
|
||||||
getShellCompl s
|
getShellCompl s
|
||||||
| s /= "" && last s /= ' ' = do
|
| s /= "" && last s /= ' ' = do
|
||||||
f <- fmap (lines . fromMaybe "") $ runProcessWithInput "/bin/bash" [] ("compgen -A file " ++ s ++ "\n")
|
f <- fmap lines $ runProcessWithInput "/bin/bash" [] ("compgen -A file " ++ s ++ "\n")
|
||||||
c <- commandCompletionFunction s
|
c <- commandCompletionFunction s
|
||||||
hPutStrLn stdout s
|
hPutStrLn stdout s
|
||||||
return . map escape . sort . nub $ f ++ c
|
return . map escape . sort . nub $ f ++ c
|
||||||
|
@@ -68,10 +68,8 @@ workspaceDir :: LayoutClass l a => String -> l a
|
|||||||
workspaceDir s = ModifiedLayout (WorkspaceDir s)
|
workspaceDir s = ModifiedLayout (WorkspaceDir s)
|
||||||
|
|
||||||
scd :: String -> X ()
|
scd :: String -> X ()
|
||||||
scd x = do x' <- io (runProcessWithInput "bash" [] ("echo -n " ++ x) `catch` \_ -> return Nothing)
|
scd x = do x' <- io (runProcessWithInput "bash" [] ("echo -n " ++ x) `catch` \_ -> return x)
|
||||||
case x' of
|
catchIO $ setCurrentDirectory x'
|
||||||
Just newDir -> catchIO $ setCurrentDirectory newDir
|
|
||||||
Nothing -> return ()
|
|
||||||
|
|
||||||
changeDir :: XPConfig -> X ()
|
changeDir :: XPConfig -> X ()
|
||||||
changeDir c = directoryPrompt c "Set working directory: " (sendMessage . Chdir)
|
changeDir c = directoryPrompt c "Set working directory: " (sendMessage . Chdir)
|
||||||
|
Reference in New Issue
Block a user