packages feed

lsfrom (empty) → 0.1

raw patch · 7 files changed

+173/−0 lines, 7 filesdep +basedep +directorydep +filepathsetup-changed

Dependencies added: base, directory, filepath, simple-cmd, simple-cmd-args

Files

+ ChangeLog.md view
@@ -0,0 +1,6 @@+# Release history for lsfrom++## 0.1 (2021-02-06)+- initial Hackage release+- supports filepaths now not just file pattern+- uses system locale collation
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2018, Jens Petersen++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * Redistributions in binary form must reproduce the above+      copyright notice, this list of conditions and the following+      disclaimer in the documentation and/or other materials provided+      with the distribution.++    * Neither the name of Jens Petersen nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Main.hs view
@@ -0,0 +1,27 @@+module Main (main) where++import SimpleCmd+import SimpleCmdArgs+import System.FilePath++import Paths_lsfrom (version)++main :: IO ()+main =+  simpleCmdArgs (Just version) "List files from pattern"+  "lsfrom lists the files in a directory that follow from the given pattern" $+  lsfrom <$> switchWith 'a' "all" "include hidden (dot) files" <*> strArg "FILEPAT"++lsfrom :: Bool -> FilePath -> IO ()+lsfrom hidden file = do+  let isdir = last file == pathSeparator+      file' = if isdir then takeDirectory file else file+      (dir,pat) = splitFileName file'+      pat' = pat ++ if isdir then [pathSeparator] else ""+  sorted <- do+    files <- cmd "ls" $ ["-a" | hidden || head pat == '.'] ++ [dir]+    lines <$> cmdStdIn "sort" [] (pat' ++ "\n" ++ files)+  let result = tail $ dropWhile (pat' /=) sorted+  mapM_ (putStrLn . (renderDir dir </>)) result+  where+    renderDir dir = if dir == "./" then "" else dir
+ README.md view
@@ -0,0 +1,22 @@+# lsfrom++`lsfrom` lists files in the current directory that start with a+particular sequence of characters and those after it with respect to+collation.++```+$ ls+A a B C+$ lsfrom a/+B+C+$ lsfrom /sy+/sys+/sysroot+/tmp+/usr+/var+```++This may be useful for continuing a script on the files in a dir+after a failure, etc.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ lsfrom.cabal view
@@ -0,0 +1,62 @@+name:                lsfrom+version:             0.1+synopsis:            List dir files starting from a specific name+description:+            `lsfrom` lists files in a directory that start with+            a particular sequence of characters and those after it+            with respect to locale collation.++            This can be useful for continuing a script on the files in a dir+            after a failure, etc.+license:             BSD3+license-file:        LICENSE+author:              Jens Petersen <petersen@redhat.com>+maintainer:          Jens Petersen <petersen@redhat.com>+copyright:           2018,2021  Jens Petersen+category:            Utility+homepage:            https://github.com/juhp/lsfrom+bug-reports:         https://github.com/juhp/lsfrom/issues+build-type:          Simple+cabal-version:       1.18+extra-doc-files:     ChangeLog.md+                     README.md++source-repository head+  type:                git+  location:            https://github.com/juhp/lsfrom.git++executable lsfrom+  main-is:             Main.hs+  other-modules:       Paths_lsfrom+  build-depends:       base < 5,+                       filepath,+                       simple-cmd,+                       simple-cmd-args+  default-language:    Haskell2010+  ghc-options:        -fwarn-missing-signatures -Wall+  if impl(ghc >= 8.0)+    ghc-options:       -Wcompat+                       -Widentities+                       -Wincomplete-uni-patterns+                       -Wincomplete-record-updates+                       -Wredundant-constraints+  if impl(ghc >= 8.2)+    ghc-options:       -fhide-source-paths+  if impl(ghc >= 8.4)+    ghc-options:       -Wmissing-export-lists+                       -Wpartial-fields+  if impl(ghc >= 8.10)+    ghc-options:       -Wunused-packages++test-suite test+  main-is: tests.hs+  type: exitcode-stdio-1.0+  hs-source-dirs: test++  default-language: Haskell2010++  ghc-options:   -Wall+  build-depends: base >= 4 && < 5+               , directory+               , filepath+               , simple-cmd
+ test/tests.hs view
@@ -0,0 +1,24 @@+import Control.Monad+import SimpleCmd+import System.Directory++lsfrom :: (FilePath, String, [String]) -> IO ()+lsfrom (dir, arg,expect) = do+  out <- withCurrentDirectory dir $+         cmdLines "lsfrom" [arg]+  unless (out == expect) $ do+    cmdN "lsfrom" [arg]+    putStrLn $ "returned> " ++ show out+    putStrLn $ "expected> " ++ show expect+    error' "failed"++tests :: [(FilePath, String,[String])]+tests =+  [ ("test/files", "B", ["B","C"])+  , ("test", "files/B/", ["files/C"])+  ]++main :: IO ()+main = do+  mapM_ lsfrom tests+  putStrLn $ show (length tests) ++ " tests run"