mirror of
https://github.com/xmonad/xmonad-contrib.git
synced 2025-08-11 10:12:15 -07:00
Catch exceptions when finding commands on PATH in Prompt.Shell
This commit is contained in:
@@ -33,7 +33,7 @@ import Codec.Binary.UTF8.String (encodeString)
|
|||||||
import Control.Exception as E
|
import Control.Exception as E
|
||||||
import Control.Monad (forM)
|
import Control.Monad (forM)
|
||||||
import Data.List (isPrefixOf)
|
import Data.List (isPrefixOf)
|
||||||
import System.Directory (doesDirectoryExist, getDirectoryContents)
|
import System.Directory (getDirectoryContents)
|
||||||
import System.Environment (getEnv)
|
import System.Environment (getEnv)
|
||||||
import System.Posix.Files (getFileStatus, isDirectory)
|
import System.Posix.Files (getFileStatus, isDirectory)
|
||||||
|
|
||||||
@@ -113,11 +113,7 @@ getCommands :: IO [String]
|
|||||||
getCommands = do
|
getCommands = do
|
||||||
p <- getEnv "PATH" `E.catch` econst []
|
p <- getEnv "PATH" `E.catch` econst []
|
||||||
let ds = filter (/= "") $ split ':' p
|
let ds = filter (/= "") $ split ':' p
|
||||||
es <- forM ds $ \d -> do
|
es <- forM ds $ \d -> getDirectoryContents d `E.catch` econst []
|
||||||
exists <- doesDirectoryExist d
|
|
||||||
if exists
|
|
||||||
then getDirectoryContents d
|
|
||||||
else return []
|
|
||||||
return . uniqSort . filter ((/= '.') . head) . concat $ es
|
return . uniqSort . filter ((/= '.') . head) . concat $ es
|
||||||
|
|
||||||
split :: Eq a => a -> [a] -> [[a]]
|
split :: Eq a => a -> [a] -> [[a]]
|
||||||
|
Reference in New Issue
Block a user