summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorjao <jao@gnu.org>2018-07-19 22:11:14 +0100
committerjao <jao@gnu.org>2018-07-19 22:11:14 +0100
commitcbde794c899d04524a486d5d0f82b8e2d889cdb8 (patch)
treefadf5babc1b9ffffec1fc3f060c332366e505fb1
parent82e186a112ac0d76a139ed572fb24b45a6b83967 (diff)
downloadxmobar-cbde794c899d04524a486d5d0f82b8e2d889cdb8.tar.gz
xmobar-cbde794c899d04524a486d5d0f82b8e2d889cdb8.tar.bz2
New ComX specifying error output string (closes #342)
-rw-r--r--changelog.md6
-rw-r--r--readme.md15
-rw-r--r--src/Commands.hs14
-rw-r--r--stack.yaml17
4 files changed, 33 insertions, 19 deletions
diff --git a/changelog.md b/changelog.md
index 20aecd4..0c2dc51 100644
--- a/changelog.md
+++ b/changelog.md
@@ -1,3 +1,9 @@
+## Version 0.28
+
+_New features_
+
+ - New `ComX`, which runs a command with custom exit error message.
+
## Version 0.27 (July, 2018)
_New features_
diff --git a/readme.md b/readme.md
index 92727bb..2022adf 100644
--- a/readme.md
+++ b/readme.md
@@ -1284,7 +1284,20 @@ _uname_ only once), while
Run Com "date" ["+\"%a %b %_d %H:%M\""] "mydate" 600
-can be used in the output template as `%mydate%`
+can be used in the output template as `%mydate%`.
+
+Sometimes, you don't mind if the command executed exits with an error,
+or you might want to display a custom message in that case. To that
+end, you can use the `ComX` variant:
+
+`ComX ProgramName Args ExitMessage Alias RefreshRate`
+
+Works like `Com`, but displaying `ExitMessage` (a string) if the
+execution fails. For instance:
+
+ Run ComX "date" ["+\"%a %b %_d %H:%M\""] "N/A" "mydate" 600
+
+will display "N/A" if for some reason the `date` invocation fails.
## Other Plugins
diff --git a/src/Commands.hs b/src/Commands.hs
index e4402fc..5b11ca3 100644
--- a/src/Commands.hs
+++ b/src/Commands.hs
@@ -48,6 +48,7 @@ class Show e => Exec e where
trigger _ sh = sh Nothing
data Command = Com Program Args Alias Rate
+ | ComX Program Args String Alias Rate
deriving (Show,Read,Eq)
type Args = [String]
@@ -56,10 +57,12 @@ type Alias = String
type Rate = Int
instance Exec Command where
- alias (Com p _ a _)
- | p /= "" = if a == "" then p else a
- | otherwise = ""
- start (Com prog args _ r) cb = if r > 0 then go else exec
+ alias (ComX p _ _ a _) =
+ if p /= "" then (if a == "" then p else a) else ""
+ alias (Com p a al r) = alias (ComX p a "" al r)
+ start (Com p as al r) cb =
+ start (ComX p as ("Could not execute command " ++ p) al r) cb
+ start (ComX prog args msg _ r) cb = if r > 0 then go else exec
where go = exec >> tenthSeconds r >> go
exec = do
(i,o,e,p) <- runInteractiveProcess prog args Nothing Nothing
@@ -71,8 +74,7 @@ instance Exec Command where
ExitSuccess -> do str <- getL
closeHandles
cb str
- _ -> do closeHandles
- cb $ "Could not execute command " ++ prog
+ _ -> closeHandles >> cb msg
-- | Work around to the Int max bound: since threadDelay takes an Int, it
diff --git a/stack.yaml b/stack.yaml
index 80ea090..a46d035 100644
--- a/stack.yaml
+++ b/stack.yaml
@@ -1,14 +1,7 @@
-resolver: lts-10.3
-allow-newer: true
+resolver: lts-12.1
packages:
- .
-# Dependency packages to be pulled from upstream that are not in the resolver
-# (e.g., acme-missiles-0.3)
-extra-deps: [iwlib-0.1.0]
-
-# Override default flag values for local packages and extra-deps
-# flags: {}
-
-# Control whether we use the GHC we find on the path
-# system-ghc: true
-
+extra-deps:
+- iwlib-0.1.0
+- parsec-numbers-0.1.0
+- alsa-mixer-0.2.0.3