From 2a432c6bb2e62b39585f0b00214241547252ce81 Mon Sep 17 00:00:00 2001 From: Arvedui Date: Sun, 2 Aug 2015 19:00:42 +0200 Subject: [PATCH] add format parameter to shell module --- i3pystatus/shell.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/i3pystatus/shell.py b/i3pystatus/shell.py index 67f4637..90261fb 100644 --- a/i3pystatus/shell.py +++ b/i3pystatus/shell.py @@ -8,6 +8,9 @@ import logging class Shell(IntervalModule): """ Shows output of shell command + + .. rubric:: Available formatters + * `{output}` — just the striped command output without newlines """ color = "#FFFFFF" @@ -16,10 +19,12 @@ class Shell(IntervalModule): settings = ( ("command", "command to be executed"), ("color", "standard color"), - ("error_color", "color to use when non zero exit code is returned") + ("error_color", "color to use when non zero exit code is returned"), + "format" ) required = ("command",) + format = "{command}" def run(self): retvalue, out, stderr = run_through_shell(self.command, enable_shell=True) @@ -32,6 +37,8 @@ class Shell(IntervalModule): elif stderr: out = stderr + out = self.format.format(command=out) + self.output = { "full_text": out if out else "Command `%s` returned %d" % (self.command, retvalue), "color": self.color if retvalue == 0 else self.error_color