packages feed

slate 0.7.0.0 → 0.8.0.0

raw patch · 3 files changed

+74/−24 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

README.md view
@@ -75,12 +75,26 @@ 00 - My <b>first</b> note. </pre> -## The `sync` command+## Configuration -You can use `slate sync` to synchronize your slates. There's no default configuration for this command, you'll have to create the file `~/.config/slate/config.toml` and add your sync command, for example:+The following configuration options can be set in `~/.config/slate/config.toml` (you'll have to create this file). +### sync++You can use `slate sync` to synchronize your slates. There's no default configuration for this command, so for it to work you'll have to add your own sync command, for example:+ ```toml sync = "git add . && git commit -m 'Update slates'; git pull --rebase origin master && git push origin master" ```  This would stage & commit every updates in `~/.config/slate/`, update your local copy and push your updates to the `origin` remote.++### status++By default, `slate status` only displays the number of notes by status. You can add a command in the `status` key that'll be used to check if the slate is synchronized or not, for example:++```toml+status = "git diff --exit-code $SLATE"+```++Where `$SLATE` will be set to `~/.config/slate/<slate name>.md`. The command must return a non-zero exit code if the slate is out of sync and zero if it's synced.
slate.cabal view
@@ -2,10 +2,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: 9b756fbd1c67b7947d10d9cad34702e44448b59d65e55924fd10ffd6ea613601+-- hash: ecbc24207c5b0e342b6af0a2f1bb74ad47382085587f7de0966aba3ba65482d2  name:           slate-version:        0.7.0.0+version:        0.8.0.0 synopsis:       A note taking CLI tool. description:    Please see the README on Github at <https://github.com/evuez/slate#readme> homepage:       https://github.com/evuez/slate#readme
src/Lib.hs view
@@ -17,8 +17,17 @@   , removeFile   , renameFile   )+import System.Exit (ExitCode(ExitFailure, ExitSuccess)) import System.FilePath.Posix (takeBaseName)-import System.Process (createProcess, cwd, shell, waitForProcess)+import System.Process+  ( StdStream(NoStream)+  , createProcess+  , cwd+  , env+  , shell+  , std_out+  , waitForProcess+  ) import Text.Toml (parseTomlDoc) import Text.Toml.Types (Node(VString)) @@ -28,17 +37,15 @@  type NoteId = Int -type MaybeNoteId = Maybe Int- type Filter = String  data Command   = Add Slate         Note   | Done Slate-         MaybeNoteId+         (Maybe NoteId)   | Todo Slate-         MaybeNoteId+         (Maybe NoteId)   | Remove Slate            NoteId   | Display Slate@@ -122,24 +129,17 @@  -- Commands execute :: Command -> IO ()-execute (Add "" n) = getSlateName >>= (\s -> execute (Add s n)) execute (Add s n) =   getSlatePath s >>= (\x -> appendFile x (" - [ ] " ++ n ++ "\n"))-execute (Done "" n) = getSlateName >>= (\x -> execute (Done x n)) execute (Done s (Just n)) = getSlatePath s >>= (\x -> markAsDone x n) execute (Done s Nothing) = getSlatePath s >>= (\x -> displaySlate x "done")-execute (Todo "" n) = getSlateName >>= (\x -> execute (Todo x n)) execute (Todo s (Just n)) = getSlatePath s >>= (\x -> markAsTodo x n) execute (Todo s Nothing) = getSlatePath s >>= (\x -> displaySlate x "todo")-execute (Remove "" n) = getSlateName >>= (\x -> execute (Remove x n)) execute (Remove s n) = getSlatePath s >>= (\x -> removeNote x n)-execute (Display "" f) = getSlateName >>= (\x -> execute (Display x f)) execute (Display s f) = getSlatePath s >>= (\x -> displaySlate x f) execute (Rename sc sn) = renameSlate sc sn-execute (Wipe "" f) = getSlateName >>= (\x -> execute (Wipe x f)) execute (Wipe s "") = getSlatePath s >>= removeFile execute (Wipe s f) = getSlatePath s >>= (\x -> wipeSlate x f)-execute (Status "") = getSlateName >>= (\x -> execute (Status x)) execute (Status s) = getSlatePath s >>= (\x -> displayStatus x) execute (Sync) = syncSlates @@ -163,10 +163,31 @@   return $ dir ++ "config.toml"  getSlatePath :: String -> IO FilePath+getSlatePath "" = do+  s <- getSlateName+  dir <- getConfigDirectory+  return $ dir ++ s ++ ".md" getSlatePath s = do   dir <- getConfigDirectory   return $ dir ++ s ++ ".md" +getConfigValue :: String -> IO (Maybe String)+getConfigValue k = do+  f <- getConfigFile+  config <- readFile f+  let Right c = parseTomlDoc "" (fromString config)+  let vs =+        case (M.lookup (fromString k) c) of+          Just (VString s) -> Just (convertString s)+          _ -> Nothing+  return vs++getConfigValueOrFail :: String -> IO String+getConfigValueOrFail k = do+  f <- getConfigFile+  c <- getConfigValue k+  return $ maybe (error $ "Key `" ++ k ++ "` not found in " ++ f ++ ".") id c+ displaySlate :: String -> String -> IO () displaySlate s "" = do   contents <- readFile s@@ -252,20 +273,35 @@  displayStatus :: FilePath -> IO () displayStatus s = do+  ss <- getSyncStatus s   contents <- readFile s   let t = length $ filter isNoteDone (lines contents)       d = length $ filter (not . isNoteDone) (lines contents)   putStr $     (show t) ++-    " done, " ++ (show d) ++ " todo (" ++ (show $ t + d) ++ " total)."+    " done, " ++ (show d) ++ " todo (" ++ (show $ t + d) ++ " total)." ++ ss +getSyncStatus :: FilePath -> IO String+getSyncStatus s = do+  v <- getConfigValue "status"+  case v of+    (Just c) -> do+      d <- getConfigDirectory+      (_, _, _, h) <-+        createProcess+          (shell c)+          {cwd = Just d, std_out = NoStream, env = Just [("SLATE", s)]}+      e <- waitForProcess h+      return $+        case e of+          ExitSuccess -> " \x1B[32mSynced ☺️\x1B[1m"+          (ExitFailure _) -> " \x1B[31mOut of sync 😕\x1B[1m"+    Nothing -> return ""+ syncSlates :: IO () syncSlates = do-  config <- (getConfigFile >>= readFile)-  dir <- getConfigDirectory-  let Right c = parseTomlDoc "" (fromString config)-  let Just (VString s) = M.lookup (fromString "sync") c-  (_, _, _, h) <--    createProcess (shell (fromString $ convertString s)) {cwd = Just dir}+  c <- getConfigValueOrFail "sync"+  d <- getConfigDirectory+  (_, _, _, h) <- createProcess (shell c) {cwd = Just d}   _ <- waitForProcess h-  return ()+  putStr "\x1B[32mDone syncing ☺️\x1B[1m"