From dcfbeabc8c6c3a775c946fb83628889d254aba48 Mon Sep 17 00:00:00 2001 From: Léana 江 Date: Mon, 22 Jun 2026 17:18:41 +0200 Subject: pass remaining battery percentage to low battery command --- src/Xmobar/Plugins/Monitors/Batt/Common.hs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'src/Xmobar') diff --git a/src/Xmobar/Plugins/Monitors/Batt/Common.hs b/src/Xmobar/Plugins/Monitors/Batt/Common.hs index ddb2b8c..d74f080 100644 --- a/src/Xmobar/Plugins/Monitors/Batt/Common.hs +++ b/src/Xmobar/Plugins/Monitors/Batt/Common.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE TypeApplications #-} ----------------------------------------------------------------------------- -- | -- Module : Plugins.Monitors.Batt.Common @@ -18,7 +19,8 @@ module Xmobar.Plugins.Monitors.Batt.Common (BattOpts(..) , Status(..) , maybeAlert) where -import System.Process (spawnCommand, waitForProcess) +import System.Environment +import System.Process (waitForProcess, createProcess_, shell, CreateProcess(env)) import Control.Monad (unless, void) import Xmobar.Plugins.Monitors.Common @@ -54,4 +56,12 @@ maybeAlert opts left = case onLowAction opts of Nothing -> return () Just x -> unless (isNaN left || actionThreshold opts < 100 * left) - $ void $ spawnCommand (x ++ " &") >>= waitForProcess + $ runCmd =<< mkShellCmd x + where + mkShellCmd command = do + selfEnv <- getEnvironment + pure (shell command) { env = Just $ [("XMOBAR_BATT_LEFT", show @Integer $ round $ 100 * left)] ++ selfEnv + } + runCmd c = do + (_,_,_,p) <- createProcess_ "maybeAlert" c + void $ waitForProcess p -- cgit v1.2.3