mirror of
https://github.com/xmonad/xmonad-contrib.git
synced 2025-08-01 20:51:52 -07:00
X.P.Man: Use System.FilePath
Instead of hand-written functions, just use what's already provided by filepath.
This commit is contained in:
@@ -32,8 +32,9 @@ import XMonad.Util.Run
|
|||||||
import XMonad.Prompt.Shell (split)
|
import XMonad.Prompt.Shell (split)
|
||||||
|
|
||||||
import System.Directory
|
import System.Directory
|
||||||
import System.Process
|
import System.FilePath (dropExtensions, (</>))
|
||||||
import System.IO
|
import System.IO
|
||||||
|
import System.Process
|
||||||
|
|
||||||
import qualified Control.Exception as E
|
import qualified Control.Exception as E
|
||||||
|
|
||||||
@@ -70,12 +71,11 @@ getMans = do
|
|||||||
p2 <- getout "manpath 2>/dev/null"
|
p2 <- getout "manpath 2>/dev/null"
|
||||||
return $ intercalate ":" $ lines $ p1 ++ p2
|
return $ intercalate ":" $ lines $ p1 ++ p2
|
||||||
let sects = ["man" ++ show n | n <- [1..9 :: Int]]
|
let sects = ["man" ++ show n | n <- [1..9 :: Int]]
|
||||||
dirs = [d ++ "/" ++ s | d <- split ':' paths, s <- sects]
|
dirs = [d </> s | d <- split ':' paths, s <- sects]
|
||||||
mans <- forM (nub dirs) $ \d -> do
|
mans <- forM (nub dirs) $ \d -> do
|
||||||
exists <- doesDirectoryExist d
|
exists <- doesDirectoryExist d
|
||||||
if exists
|
if exists
|
||||||
then map (stripExt . stripSuffixes [".gz", ".bz2"]) <$>
|
then map dropExtensions <$> getDirectoryContents d
|
||||||
getDirectoryContents d
|
|
||||||
else return []
|
else return []
|
||||||
return $ uniqSort $ concat mans
|
return $ uniqSort $ concat mans
|
||||||
|
|
||||||
@@ -101,15 +101,3 @@ getCommandOutput s = do
|
|||||||
E.evaluate (length output)
|
E.evaluate (length output)
|
||||||
hClose perr
|
hClose perr
|
||||||
return output
|
return output
|
||||||
|
|
||||||
stripExt :: String -> String
|
|
||||||
stripExt = reverse . drop 1 . dropWhile (/= '.') . reverse
|
|
||||||
|
|
||||||
stripSuffixes :: Eq a => [[a]] -> [a] -> [a]
|
|
||||||
stripSuffixes sufs fn =
|
|
||||||
head . catMaybes $ map (`rstrip` fn) sufs ++ [Just fn]
|
|
||||||
|
|
||||||
rstrip :: Eq a => [a] -> [a] -> Maybe [a]
|
|
||||||
rstrip suf lst
|
|
||||||
| suf `isSuffixOf` lst = Just $ take (length lst - length suf) lst
|
|
||||||
| otherwise = Nothing
|
|
||||||
|
Reference in New Issue
Block a user