summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJose Antonio Ortega Ruiz <jao@gnu.org>2010-12-07 22:15:36 +0100
committerJose Antonio Ortega Ruiz <jao@gnu.org>2010-12-07 22:15:36 +0100
commitcfa095f79f9780c62ad29a13e9000666177c9db8 (patch)
treea97e55db2431690f7f3399d7da8a513836adf71f
parent68dada84d0e3f820a38395051b374d14e12d5ff1 (diff)
downloadxmobar-cfa095f79f9780c62ad29a13e9000666177c9db8.tar.gz
xmobar-cfa095f79f9780c62ad29a13e9000666177c9db8.tar.bz2
Run once commands by setting rate to 0 in Command (issue 26)
Just specify a 0 (or negative) rate in the Command plugin. E.g. Run Comand "uname" ["-s", "-r"] "uname" 0
-rw-r--r--Commands.hs19
1 files changed, 9 insertions, 10 deletions
diff --git a/Commands.hs b/Commands.hs
index 6bbe95b..8baaaf5 100644
--- a/Commands.hs
+++ b/Commands.hs
@@ -57,22 +57,21 @@ instance Exec Command where
alias (Com p _ a _)
| p /= "" = if a == "" then p else a
| otherwise = ""
- start (Com prog args _ r) cb = do go
- where go = do
- (i,o,e,p) <- runInteractiveCommand (prog ++ concat (map (' ':) args))
+ start (Com prog args _ r) cb = if r > 0 then go else exec
+ where go = exec >> tenthSeconds r >> go
+ exec = do
+ (i,o,e,p) <- runInteractiveCommand (unwords (prog:args))
exit <- waitForProcess p
- let closeHandles = do
- hClose o
- hClose i
- hClose e
+ let closeHandles = hClose o >> hClose i >> hClose e
case exit of
ExitSuccess -> do
- str <- catch (hGetLineSafe o) (\(SomeException _) -> return "")
+ str <- catch (hGetLineSafe o)
+ (\(SomeException _) -> return "")
closeHandles
cb str
_ -> do closeHandles
cb $ "Could not execute command " ++ prog
- tenthSeconds r >> go
+
-- | Work arount to the Int max bound: since threadDelay takes an Int, it
-- is not possible to set a thread delay grater than about 45 minutes.
@@ -81,5 +80,5 @@ tenthSeconds :: Int -> IO ()
tenthSeconds s | s >= x = do threadDelay y
tenthSeconds (x - s)
| otherwise = threadDelay (s * 100000)
- where y = (maxBound :: Int)
+ where y = maxBound :: Int
x = y `div` 100000