From 6bee5a3331cf7fadab2aa30b6fbe43dd9ef7be24 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Sun, 2 Oct 2016 16:52:58 +0200 Subject: options! --- custom/notify-user.nix | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'custom') 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 { import System.Exit (exitWith, ExitCode(..)) import Data.List (isPrefixOf, dropWhile, dropWhileEnd, init) - import Data.Char (isSpace) + import Data.Char (isSpace, toLower, toUpper) import Control.Monad (forM_, void) import qualified Libnotify as Notify import Data.Monoid + import System.Console.GetOpt.Simple + + import qualified Data.Map as Map + + import Data.Maybe + import Text.Read (readMaybe) + main = do envFiles <- glob "/home/${user}/.dbus/session-bus/*" forM_ envFiles $ \envFile -> do @@ -29,18 +36,28 @@ stdenv.mkDerivation { setEnv "DBUS_SESSION_BUS_ADDRESS" sessionAddr lines <- lines <$> getContents case lines of - ((trim -> app):(trim -> summary):(trim . unlines -> contents)) -> do - Notify.display_ $ Notify.appName app <> Notify.summary summary <> Notify.body contents + ((trim -> summary):(trim . unlines -> contents)) -> do + (opts, _) <- flip getUsingConf [] [ (arg, "urgency", Optional, "") + , (arg, "app-name", Optional, "") + , (arg, "category", Optional, "") + ] + let + urgency = fromMaybe Notify.Normal $ readMaybe . caseForRead =<< Map.lookup "urgency" opts + appName = fromMaybe "notify-${user}" $ Map.lookup "app-name" opts + category = fromMaybe "" $ Map.lookup "category" opts + Notify.display_ $ Notify.summary summary <> Notify.body contents <> Notify.appName appName <> Notify.urgency urgency <> Notify.category category _ -> exitWith $ ExitFailure 2 where trim = dropWhileEnd isSpace . dropWhile isSpace unQuote ('\''':xs) = init xs unQuote ('"':xs) = init xs unQuote xs = xs + caseForRead [] = [] + caseForRead (x:xs) = toUpper x : map toLower xs ''; }; phases = [ "buildPhase" "installPhase" ]; buildPhase = '' - ${ghcWithPackages (p: with p; [ Glob process libnotify ])}/bin/ghc -odir . -hidir . $src -o notify-${user} + ${ghcWithPackages (p: with p; [ Glob process libnotify getopt-simple containers ])}/bin/ghc -odir . -hidir . $src -o notify-${user} ''; installPhase = '' mkdir -p $out/bin -- cgit v1.2.3