X Tutup
The Wayback Machine - https://web.archive.org/web/20230604185028/https://github.com/jorgebucaran/spark.fish
Skip to content

jorgebucaran/spark.fish

main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
January 16, 2021 14:39
January 1, 2021 01:15
January 16, 2021 14:39
January 12, 2019 11:30
January 1, 2021 02:00

spark.fish

Sparklines for Fish.

Unofficial port of spark.sh with --min, --max flags and improved performance.

Installation

Install with Fisher:

fisher install jorgebucaran/spark.fish

Quickstart

You want to visualize a range of numbers right in your terminal.

$ spark 1 2 4 8
▁▂▄█

And here is a sequence of random numbers.

$ seq 64 | sort --random-sort | spark
▅▄▂▇▂▅▆▄▃█▂▅▄▁▆▆▃█▄▁▇▅▂▃▇▃▃▄▇▄▅▆▇▂▅▁▇▁▄▂▆▅▃█▇▆▆▅▆▃▄▄▇▃▂▇█▅▃█▁▂▂▆

You can set the --min=<number> or --max=<number> values for your sparkline too.

$ seq 10 20 | spark
▁▂▂▃▄▄▅▆▇▇█
$ seq 10 20 | spark --min=0
▄▅▅▆▆▆▇▇▇██
$ seq 10 20 | spark --min=0 --max=30
▃▄▄▄▄▄▅▅▅▅▆

Wicked Cool Usage

Most of the examples in this section are derived from the original Wicked Cool Usage wiki, ported to Fish.

Line lengths.

$ awk \$0=length (functions --details spark) | spark
▃▆▃▃▃▄▃▂▄▄▄▅▂▄▅▂▆▁▅▂▅▅▃▂▂▆▃█▂▁▁▁

Number of commits in a repo, by author.

$ git shortlog --summary | string match --regex "\d+" | spark
█▁▁▁▃▁▁▄▁▁▁

Total run time of processes.

$ ps -A | string replace --filter --regex -- ".*(\d+):(\d+).*" "\$1 * 3600 + \$2 * 60" | bc | spark
▇▁▂▁▆▁▂▂▁▃▁▃▁▁▁▆▁▁▁▂▁▃▂▁▁▃▁▁▁▁▁▂▁▁▂▁▁▁▁▁▆▂▃▂▁▂▃▁▆▁▁▁▂▁▁▁▁▃▂▂▁▇▁▁▁▁▆

LOC added per commit over the last week.

$ git diff @~7 --numstat | string replace --regex -- "(^\d+).*" "\$1" | spark
▁▁▁▁▁▁▁▁▂▁▁▁▁▁▁▂▂▃█▄▁▁

A moving wave through the terminal.

for i in (seq 100)
   for j in (seq (math $COLUMNS - 1))
      math "ceil(6 * cos(($i + $j) * pi / 5))"
   end | spark | read sparks
   echo -n $sparks\r && sleep .1
end
▆▄▂▁▂▄▆▇█▇▆▄▂▁▂▄▆▇█▇▆▄▂▁▂▄▆▇█▇▆▄▂▁▂▄▆▇█▇▆▄▂▁▂▄▆▇█▇▆▄▂▁▂▄▆▇█

Performance

Spark is faster than spark.sh, reading and writing relatively large datasets under milliseconds.

$ time seq 2000 | sort --random-sort | spark
________________________________________________________
Executed in   27.21 millis    fish           external
   usr time   26.40 millis    0.57 millis   25.83 millis
   sys time    4.87 millis    1.58 millis    3.29 millis

$ time seq 2000 | sort --random-sort | spark.sh
________________________________________________________
Executed in    2.73 secs    fish           external
   usr time    2.72 secs    0.33 millis    2.72 secs
   sys time    0.02 secs    1.47 millis    0.02 secs

License

MIT

X Tutup