Add parser-friendly output mode
maximbaz opened this issue · 0 comments
Hi,
First of all, love the tool, awesome idea!
I got interested to use progress
as a framework for building other tools on top of it, specifically an indicator for my status panel that would show the currently running operations, and I found it quite difficult to parse the values out of the progress
command. Hence this feature request 🙂
Just to give you an example, suppose I want to display on my status panel just the command name (cp
, mv
, etc.) and the current progress percentage, e.g. cp 73% rsync 25%
. In addition, I want to exclude certain commands (e.g. gpg
) and I want to exclude 0%
and 100%
values.
Here's the current code that is capable of doing that:
progress -q | sed 's/\[[^]]*\] //g' | awk 'BEGIN { ORS=" " } NR%3==1 { op=$1 } NR%3==2 { pct=($1+0); if (op != "gpg" && pct > 0 && pct < 100) { print op, $1 } }'
Not very readable, and took time to come up with.
What made it difficult to parse was this:
- Multiple lines per entry (specifically, three lines)
- No easy separator between columns (the most obvious idea is to split on space, but e.g. PID can be
[12345]
and[ 1234]
)
I stumbled upon this blog post, and I must say this would probably be ideal if progress
had a --json
flag, which would output everything in JSON format, which is standard, predictable, and super easy to parse with jq
.
I also saw #131 and initially got excited by it, but then I realized it doesn't print all the fields, so it isn't really a solution.
What do you think about --json
option?