Hacker News new | past | comments | ask | show | jobs | submit login
Show HN: Simple tool for creating command-line bar charts (github.com/turkeymcmac)
86 points by jwmhjwmh on Aug 28, 2021 | hide | past | favorite | 23 comments



As someone else pointed out, this definitely gets points for using sh/awk.

Just wanted to mention that gnuplot also has a "dumb" output option that will generate ascii plots in the terminal. Thay is usually my go-to for this use case.


+1 gnuplot is awesome

But this showHN project pretty cool too



Nice, this is exactly what I've been looking for for a while now. Especially the real-time streaming mode. Thanks for posting!


Anyway we could use this with realtime rendering? For eg: I pipe data from top command to this script to see graphs/charts change it dynamically?


    watch -n1 ./barchart -w 80 data


You would probably need a wrapper script to do this. The script could periodically clear the screen and call "barchart" with the new input data, re-rendering the chart from scratch.

"barchart" is a very simple shell script that doesn't do much on its own.


Slightly relevant: The program "htop" displays CPU usage with bars on the command line. https://htop.dev/


Nice one!

I had some fun creating a minimal (7 lines) bash implementation for bars using reverse video mode awhile ago.

https://eskerda.com/minimal-bash-progress-bar-ansi-escape-se...


As an intermediate Linux user I’ve found shell to be both wondrously powerful as well as frustratingly difficult to write.

You can do so much. And the model of chaining known, stable programs together is elegant.

But it feels hard to write and maintain good code with. Even in this barchart program there’s a string of awk within this code.

So it got me wondering: is there any high quality text editor or IDE support for shell scripts? Perhaps one that even understands or looks at the inputs and outputs to other programs and understands hen you’re writing awk or sed or whatnot inside it?

And what about the concept of a higher level ergonomic language that compiles to a shell script?


There exist more modern shells like Fish Shell and Oil Shell. I haven't used them, but they're probably nicer to use than POSIX shell. I'm sure they have pipes and stuff too.


I use Fish, and can confirm that it has pipes, along with string substitution, redirection (>, >>, 2>, etc.), functions, etc.

The difference is that fish's keywords are closer to programming languages' (all blocks end with `end`, no esac nor fi), fish kind of looks like Ruby.


There is a LSP for shell: shellcheck


I would rather use this: https://github.com/Evizero/UnicodePlots.jl along with a little scripting.


Hi jwmhjwmh - thanks for posting this. I just wanted to add, for me, two important features of a utility like this are 1. to accept input from a pipe, and 2. to specify a delimiter. My usual use would be

  data source | processing | plot
E.g. a csv, cut or awk, then either print the data or plot. The features I suggested make this workflow easier, but I don't know how common that is. I'd be interested to know how other people would use this.


The script does accept input from a pipe, just as Awk does. Specifying a delimiter seems like it should be doable.

To answer your question, I mainly use this for counting lines of code:

    cloc --by-file --csv src/ | awk -F, '/^C/{print$5,$2}' | barchart | less
(The above pipeline counts the lines of C code in files in the src directory.)

EDIT: Actually, the script can pretty easily support alternative delimiters. Let's say you wanted "," as a delimiter. Instead of writing:

    barchart data
Just write:

    sed 's/,/ /' data | barchart
(This sed invocation will only replace the first comma, so it won't mess with your labels.)


Have you tried the `tokei` tool for counting lines of code? It can also output in machine-readable formats IIRC.


I just tried it at your suggestion. I do like the JSON output.


"The script should work with any POSIX shell."

Nice work!


sh for arg parsing and configuration detection (cols). awk for the actual work.

No fluff. Straight to the point. Just Works.

Congrats to the author.


nice little project :)

on a tangent I was playing with https://github.com/piccolomo/plotext for a bit (especially on a data analysis server connected over ssh it's quite useful, if you don't have the bandwidth to start a jupyter notebook).


This is really useful :)


Nice and Supercool!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: