1
0
Fork 0

Improve taskwarrior notifications

This commit is contained in:
Malte Brandy 2020-01-19 19:55:01 +01:00
parent a276483383
commit a53cd9c5b0
No known key found for this signature in database
GPG key ID: 226A2D41EF5378C9
2 changed files with 29 additions and 6 deletions

View file

@ -36,6 +36,7 @@
]; ];
imports = [ imports = [
"DBus.Notify" "DBus.Notify"
"DBus.Client (clientErrorMessage)"
"System.IO" "System.IO"
"Data.Aeson" "Data.Aeson"
"Control.Monad" "Control.Monad"
@ -64,8 +65,11 @@
String description <- HM.lookup "description" task2 String description <- HM.lookup "description" task2
pure (description, printMap diff) pure (description, printMap diff)
Control.Monad.forM_ description $ \(d,b) -> do Control.Monad.forM_ description $ \(d,b) -> do
client <- connectSession client <- try connectSession
notify client blankNote { summary = [i|Modified task #{d}|], body = Just $ Text b, expiry = Milliseconds 15000 } either
(BS.hPut stderr . encodeUtf8 . clientErrorMessage)
(\c -> void $ notify c blankNote { summary = [i|Modified task #{d}|], body = Just $ Text b, expiry = Milliseconds 15000 })
client
BS.hPut stdout input2 BS.hPut stdout input2
''; '';
on-add = writeHaskellScript { on-add = writeHaskellScript {
@ -78,9 +82,12 @@
let description = do let description = do
Object task <- decode $ toLazy input :: Maybe Value Object task <- decode $ toLazy input :: Maybe Value
pure . printMap . fmap That $ task pure . printMap . fmap That $ task
Control.Monad.forM_ description $ \d -> do whenJust description $ \d -> do
client <- connectSession client <- try connectSession
notify client blankNote { summary = "New Task", body = Just $ Text d, expiry = Milliseconds 15000 } either
(BS.hPut stderr . encodeUtf8 . clientErrorMessage)
(\c -> void $ notify c blankNote { summary = "New Task", body = Just $ Text d, expiry = Milliseconds 15000 })
client
BS.hPut stdout input BS.hPut stdout input
''; '';
in { in {
@ -92,6 +99,22 @@
target = ".task/hooks/on-modify.notification"; target = ".task/hooks/on-modify.notification";
source = "${on-modify}/bin/on-modify"; source = "${on-modify}/bin/on-modify";
}; };
"add-kassandra-notification" = {
target = ".task/hooks/on-add.kassandra-notification";
executable = true;
text = ''
#!${pkgs.bash}/bin/bash
tee >(nc 127.0.0.1 6545)
'';
};
"modify-kassandra-notification" = {
target = ".task/hooks/on-modify.kassandra-notification";
executable = true;
text = ''
#!${pkgs.bash}/bin/bash
tail -n 1 | tee >(nc 127.0.0.1 6545)
'';
};
}; };
programs.taskwarrior = let cfg = config.m-0.private.taskwarrior; programs.taskwarrior = let cfg = config.m-0.private.taskwarrior;
in { in {

View file

@ -67,7 +67,7 @@ rec {
import qualified Data.ByteString as BS import qualified Data.ByteString as BS
import qualified Data.Text as Text import qualified Data.Text as Text
import System.Environment (getArgs) import System.Environment (getArgs)
import Control.Exception (bracket) import Control.Exception (bracket, try)
import Data.String.Interpolate (i) import Data.String.Interpolate (i)
${builtins.concatStringsSep "\n" (map (x: "import ${x}") imports)} ${builtins.concatStringsSep "\n" (map (x: "import ${x}") imports)}