Skip to content

Instantly share code, notes, and snippets.

@michelk
Last active May 15, 2020 11:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michelk/76c5d86cd158cc3d2cc955ae6adc1dff to your computer and use it in GitHub Desktop.
Save michelk/76c5d86cd158cc3d2cc955ae6adc1dff to your computer and use it in GitHub Desktop.
module Main where
import Control.Monad
import Data.List
import System.Directory
import System.Environment
import System.Exit
import System.FilePath.Posix
import System.Process
_ZK_DIR_NAME :: FilePath
_ZK_DIR_NAME = ".zk"
main :: IO ()
main = do
args <- getArgs
when
(length args == 0 || (length args == 1 && head args `elem` ["-h", "--help"]))
( putStrLn
("Wrapper for 'neuron' which searches for a" <> _ZK_DIR_NAME <> "directory \
\ as zettelkasten in the descending directory tree")
>> exitSuccess
)
pwd <- getCurrentDirectory
let ds = splitDirectories pwd
zkDir <- findZkDir _ZK_DIR_NAME ds
ext <-
case zkDir of
Nothing -> do
die ("Could not find directory " <> _ZK_DIR_NAME)
Just d -> do
let prog = ["neuron", "-d", d]
let cmd = intercalate " " (prog ++ args)
system cmd
return ()
findZkDir :: FilePath -> [FilePath] -> IO (Maybe FilePath)
findZkDir _ [] = return Nothing
findZkDir zkdir ds = do
let dAbs = joinPath (ds ++ [zkdir])
found <- doesDirectoryExist dAbs
if found
then return (Just dAbs)
else findZkDir zkdir (init ds)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment