summaryrefslogtreecommitdiff
path: root/custom
diff options
context:
space:
mode:
Diffstat (limited to 'custom')
-rw-r--r--custom/notify-user.nix25
1 files changed, 21 insertions, 4 deletions
diff --git a/custom/notify-user.nix b/custom/notify-user.nix
index 17123e47..c2ad3472 100644
--- a/custom/notify-user.nix
+++ b/custom/notify-user.nix
@@ -15,13 +15,20 @@ stdenv.mkDerivation {
15 import System.Exit (exitWith, ExitCode(..)) 15 import System.Exit (exitWith, ExitCode(..))
16 16
17 import Data.List (isPrefixOf, dropWhile, dropWhileEnd, init) 17 import Data.List (isPrefixOf, dropWhile, dropWhileEnd, init)
18 import Data.Char (isSpace) 18 import Data.Char (isSpace, toLower, toUpper)
19 19
20 import Control.Monad (forM_, void) 20 import Control.Monad (forM_, void)
21 21
22 import qualified Libnotify as Notify 22 import qualified Libnotify as Notify
23 import Data.Monoid 23 import Data.Monoid
24 24
25 import System.Console.GetOpt.Simple
26
27 import qualified Data.Map as Map
28
29 import Data.Maybe
30 import Text.Read (readMaybe)
31
25 main = do 32 main = do
26 envFiles <- glob "/home/${user}/.dbus/session-bus/*" 33 envFiles <- glob "/home/${user}/.dbus/session-bus/*"
27 forM_ envFiles $ \envFile -> do 34 forM_ envFiles $ \envFile -> do
@@ -29,18 +36,28 @@ stdenv.mkDerivation {
29 setEnv "DBUS_SESSION_BUS_ADDRESS" sessionAddr 36 setEnv "DBUS_SESSION_BUS_ADDRESS" sessionAddr
30 lines <- lines <$> getContents 37 lines <- lines <$> getContents
31 case lines of 38 case lines of
32 ((trim -> app):(trim -> summary):(trim . unlines -> contents)) -> do 39 ((trim -> summary):(trim . unlines -> contents)) -> do
33 Notify.display_ $ Notify.appName app <> Notify.summary summary <> Notify.body contents 40 (opts, _) <- flip getUsingConf [] [ (arg, "urgency", Optional, "")
41 , (arg, "app-name", Optional, "")
42 , (arg, "category", Optional, "")
43 ]
44 let
45 urgency = fromMaybe Notify.Normal $ readMaybe . caseForRead =<< Map.lookup "urgency" opts
46 appName = fromMaybe "notify-${user}" $ Map.lookup "app-name" opts
47 category = fromMaybe "" $ Map.lookup "category" opts
48 Notify.display_ $ Notify.summary summary <> Notify.body contents <> Notify.appName appName <> Notify.urgency urgency <> Notify.category category
34 _ -> exitWith $ ExitFailure 2 49 _ -> exitWith $ ExitFailure 2
35 where 50 where
36 trim = dropWhileEnd isSpace . dropWhile isSpace 51 trim = dropWhileEnd isSpace . dropWhile isSpace
37 unQuote ('\''':xs) = init xs 52 unQuote ('\''':xs) = init xs
38 unQuote ('"':xs) = init xs 53 unQuote ('"':xs) = init xs
39 unQuote xs = xs 54 unQuote xs = xs
55 caseForRead [] = []
56 caseForRead (x:xs) = toUpper x : map toLower xs
40 ''; }; 57 ''; };
41 phases = [ "buildPhase" "installPhase" ]; 58 phases = [ "buildPhase" "installPhase" ];
42 buildPhase = '' 59 buildPhase = ''
43 ${ghcWithPackages (p: with p; [ Glob process libnotify ])}/bin/ghc -odir . -hidir . $src -o notify-${user} 60 ${ghcWithPackages (p: with p; [ Glob process libnotify getopt-simple containers ])}/bin/ghc -odir . -hidir . $src -o notify-${user}
44 ''; 61 '';
45 installPhase = '' 62 installPhase = ''
46 mkdir -p $out/bin 63 mkdir -p $out/bin