little xargs eqivilant as a pure function
This commit is contained in:
parent
0583b4686a
commit
a3a567da13
1 changed files with 17 additions and 0 deletions
|
@ -85,3 +85,20 @@ prop_idempotent_shellEscape :: String -> Bool
|
|||
prop_idempotent_shellEscape s = [s] == (shellUnEscape . shellEscape) s
|
||||
prop_idempotent_shellEscape_multiword :: [String] -> Bool
|
||||
prop_idempotent_shellEscape_multiword s = s == (shellUnEscape . unwords . map shellEscape) s
|
||||
|
||||
{- Segements a list of filenames into groups that are all below the manximum
|
||||
- command-line length limit. Does not preserve order. -}
|
||||
segmentXargs :: [FilePath] -> [[FilePath]]
|
||||
segmentXargs l = go l [] 0 []
|
||||
where
|
||||
go [] c _ r = c:r
|
||||
go (f:fs) c accumlen r
|
||||
| len < maxlen && newlen > maxlen = go (f:fs) [] 0 (c:r)
|
||||
| otherwise = go fs (f:c) newlen r
|
||||
where
|
||||
len = length f
|
||||
newlen = accumlen + len
|
||||
|
||||
{- 10k of filenames per command, well under Linux's 20k limit;
|
||||
- allows room for other parameters etc. -}
|
||||
maxlen = 10240
|
||||
|
|
Loading…
Add table
Reference in a new issue