Last active
May 15, 2020 11:21
-
-
Save michelk/76c5d86cd158cc3d2cc955ae6adc1dff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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