Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

mylocate 修正

  • Loading branch information...
commit 5a03762098e9a44eb9c99e391cfe77680dbe2f31 1 parent 35cac78
依云 authored
4 List/List.hs
View
@@ -2,7 +2,7 @@ module List.List (
lookupWith,
) where
-lookupWith :: (a -> Bool) -> [(a, b)] -> Maybe b
+lookupWith :: (a -> Bool) -> [(a, b)] -> Maybe (a, b)
lookupWith _ [] = Nothing
-lookupWith p ((x, y):xs) | p x = Just y
+lookupWith p ((x, y):xs) | p x = Just (x, y)
| otherwise = lookupWith p xs
5 lib/Control/Function.hs
View
@@ -7,11 +7,6 @@ module Control.Function (
import Data.Maybe (isJust)
--- |Applies a list of functions until one returns a Right value and returns it,
--- or returns a Left value if no Right
-applyEither :: [(a -> Either a a)] -> a -> Either a a
-applyEither = applyUntil isRight
-
-- |Applies a list of functions until a Just value is got
applyMaybe :: [(a -> Maybe b)] -> a -> Maybe b
applyMaybe = applyUntil isJust
20 locatewrapper/mylocate.hs
View
@@ -15,8 +15,7 @@ import System.Process (
StdStream(..),
)
-import Control.Function (applyEither)
-import Text.String (dropPrefix)
+import List.List (lookupWith)
main = do
(out, p) <- doLocate
@@ -41,10 +40,15 @@ transform :: String -> String
transform = unlines . map transformLine . lines
transformLine :: String -> String
-transformLine s = case applyEither funcs s of
- Left r -> r
- Right r -> '~' : r
- where funcs = map dropPrefix prefixesToHome
+transformLine s = case lookupWith (`isPrefixOf` s) prefixesMap of
+ Just (p, r) -> r ++ drop (length p) s
+ Nothing -> s
-prefixesToHome :: [String]
-prefixesToHome = ["/home/.ecryptfs/lilydjwg/public", "/home/lilydjwg"]
+prefixesMap :: [(String, String)]
+prefixesMap = [
+ ("/home/lilydjwg", "~"),
+ ("/home/.ecryptfs/lilydjwg/public/aMule", "~/.aMule"),
+ ("/home/.ecryptfs/lilydjwg/public/goldendict", "~/.goldendict/goldendict"),
+ ("/home/.ecryptfs/lilydjwg/public/VirtualBox", "~/.VirtualBox"),
+ ("/home/.ecryptfs/lilydjwg/public", "~")
+ ]
Please sign in to comment.
Something went wrong with that request. Please try again.