summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAudreyTang <>2008-08-07 04:05:01 (GMT)
committerLuite Stegeman <luite@luite.com>2008-08-07 04:05:01 (GMT)
commitd6b7797386d32cd3720453c74abab8799c237bed (patch)
tree37810288289e3f2387d28158ab45d059320c1a41
version 0.0.1HEAD0.0.1master
-rw-r--r--LICENSE18
-rwxr-xr-xSetup.lhs5
-rw-r--r--mdo.cabal18
-rw-r--r--mdo.hs33
4 files changed, 74 insertions, 0 deletions
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..5ed9bd9
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,18 @@
+Copyright 2008 by Audrey Tang
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to
+deal in the Software without restriction, including without limitation the
+rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+sell copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/Setup.lhs b/Setup.lhs
new file mode 100755
index 0000000..a81e9d2
--- /dev/null
+++ b/Setup.lhs
@@ -0,0 +1,5 @@
+#!/usr/bin/env runhaskell
+> module Main where
+> import Distribution.Simple
+> main :: IO ()
+> main = defaultMain
diff --git a/mdo.cabal b/mdo.cabal
new file mode 100644
index 0000000..4c0c5d9
--- /dev/null
+++ b/mdo.cabal
@@ -0,0 +1,18 @@
+name: mdo
+version: 0.0.1
+copyright: 2008 Audrey Tang
+license: BSD3
+license-file: LICENSE
+author: Audrey Tang <audreyt@audreyt.org>
+maintainer: Audrey Tang <audreyt@audreyt.org>
+synopsis: Command-line tool to run a command on each of the items.
+description: Usage: mdo COMMAND [BEFORE... --] ITEMS... [--- AFTER...]
+ Run COMMAND on each of the ITEMS.
+ Arguments in BEFORE are used as initial arguments to each invocation.
+ Arguments in AFTER are used as trailing arguments to each invocation.
+stability: experimental
+build-type: Simple
+category: Console
+executable: mdo
+build-depends: base, process
+main-is: mdo.hs
diff --git a/mdo.hs b/mdo.hs
new file mode 100644
index 0000000..83cc0a9
--- /dev/null
+++ b/mdo.hs
@@ -0,0 +1,33 @@
+import System.Cmd
+import System.Environment
+
+main :: IO ()
+main = do
+ args <- getArgs
+ case args of
+ [] -> usage
+ (cmd:rest) -> parseBefore cmd rest
+ where
+ parseBefore cmd rest = case break (== "--") (reverse rest) of
+ (_, []) -> parseAfter cmd [] rest
+ (after, (_:before)) -> parseAfter cmd before (reverse after)
+ parseAfter cmd before rest = case break (== "---") rest of
+ (_, []) -> run cmd before rest []
+ (xs, (_:after)) -> run cmd before xs after
+
+run :: String -> [String] -> [String] -> [String] -> IO ()
+run cmd before args after = (`mapM_` args) $ \arg -> do
+ rawSystem cmd (before ++ (arg:after))
+
+usage :: IO ()
+usage = mapM_ putStrLn
+ [ ""
+ , "Usage: mdo COMMAND [BEFORE... --] ITEMS... [--- AFTER...]"
+ , ""
+ , " Run COMMAND on each of the ITEMS."
+ , ""
+ , " Arguments in BEFORE are used as initial arguments to each invocation."
+ , ""
+ , " Arguments in AFTER are used as trailing arguments to each invocation."
+ , ""
+ ]