aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoraidan <torrinfail@gmail.com>2020-08-27 04:47:07 +0000
committeraidan <torrinfail@gmail.com>2020-08-27 04:47:07 +0000
commit500b1fbb0f5d91f80f6f86067f898c72f4b2aa58 (patch)
tree53df9c15330758b244bdbb9f497fb30196601867
parent904e40790870aedbc579d9093b6786b0c1500a96 (diff)
fixed output from commands without a newline end.
This is useful when using commands such as tr -d '\n' to strip newlines from output.
-rw-r--r--dwmblocks.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/dwmblocks.c b/dwmblocks.c
index 5abd10d..b6f696f 100644
--- a/dwmblocks.c
+++ b/dwmblocks.c
@@ -50,16 +50,17 @@ static void (*writestatus) () = setroot;
void getcmd(const Block *block, char *output)
{
strcpy(output, block->icon);
- char *cmd = block->command;
- FILE *cmdf = popen(cmd,"r");
+ FILE *cmdf = popen(block->command, "r");
if (!cmdf)
return;
- char c;
int i = strlen(block->icon);
fgets(output+i, CMDLENGTH-i-delimLen, cmdf);
i = strlen(output);
- if (delim[0] != '\0' && --i)
- strncpy(output+i, delim, delimLen);
+ if (delim[0] != '\0') {
+ //only chop off newline if one is present at the end
+ i = output[i-1] == '\n' ? i-1 : i;
+ strncpy(output+i, delim, delimLen);
+ }
else
output[i++] = '\0';
pclose(cmdf);