Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Set working directory to NN_HOME and work there.

  • Loading branch information...
commit 69f6eaab3105d6e632a8670a925f0be217066f45 1 parent 3f40bd4
@bjornbm authored
Showing with 16 additions and 14 deletions.
  1. +6 −4 NNUtil.hs
  2. +10 −10 nn.hs
View
10 NNUtil.hs
@@ -10,17 +10,19 @@ import System.FilePath
import System.Process
--- | Find files. We used the ASCII NULL terminated paths since file
+-- | Find files. We use the ASCII NULL terminated paths since file
-- names can contain @\n@ and would get split by @lines@.
-mdfind dir args = endBy "\0" <$> readProcess "mdfind" (stdArgs dir ++ args) ""
+mdfind args = do
+ dir <- getCurrentDirectory
+ endBy "\0" <$> readProcess "mdfind" (stdArgs dir ++ args) ""
where
stdArgs dir = [ "-onlyin", dir
, "-0"
- -- , "name:_" -- FIXME this is an embarrasing kludge!
]
-- | List all files in the directory except for hidden files.
-mdlist dir = filter ((/='.') . head) <$> getDirectoryContents dir
+mdlist = getDirectoryContents =<< getCurrentDirectory
+-- mdlist = filter ((/='.') . head) <$> getDirectoryContents "."
-- Regex patterns.
obsP = "^\\+?"
View
20 nn.hs
@@ -28,9 +28,9 @@ main = do
dir <- getEnv "NN_HOME"
setCurrentDirectory dir
case mode of
- List _ _ _ -> list dir mode
+ List _ _ _ -> list mode
Cat _ -> print mode
- otherwise -> list dir mode
+ otherwise -> list mode
listMode = List { exec = def &= help "Pass files as arguments to COMMAND" &= typ "COMMAND"
@@ -39,18 +39,18 @@ listMode = List { exec = def &= help "Pass files as arguments to COMMAND" &= typ
}
catMode = Cat { iD = def &= args &= typ "FILE ID" }
-getFiles dir [] = do
- processFiles <$> mdlist dir
+getFiles [] = do
+ processFiles <$> mdlist
-getFiles dir terms = do
- processFiles <$> mdfind dir terms
+getFiles terms = do
+ processFiles <$> mdfind terms
-- List the names of files matching the terms.
-list dir (List _ Nothing terms) = putStr . unlines =<< getFiles dir terms
+list (List _ Nothing terms) = putStr . unlines =<< getFiles terms
-- Apply command specified with --exec to files matching the terms.
-list dir (List _ (Just exec) terms) = do
- files <- getFiles dir terms
+list (List _ (Just exec) terms) = do
+ files <- getFiles terms
let cmd:args = words exec
code <- rawSystem cmd (args ++ files)
case code of
@@ -58,4 +58,4 @@ list dir (List _ (Just exec) terms) = do
otherwise -> print code
-processFiles = sort . filter (=~ filePattern0) . fmap takeFileName
+processFiles = id -- sort . filter (=~ filePattern0) . fmap takeFileName
Please sign in to comment.
Something went wrong with that request. Please try again.