From 8600374371f91843064441113f4023cda1730877 Mon Sep 17 00:00:00 2001 From: Roger Gonzalez Date: Sat, 18 Mar 2023 16:40:57 -0300 Subject: General fish fixes and updates --- .config/fish/functions/spark.fish | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 .config/fish/functions/spark.fish (limited to '.config/fish/functions/spark.fish') diff --git a/.config/fish/functions/spark.fish b/.config/fish/functions/spark.fish new file mode 100644 index 00000000..0bbe6ff0 --- /dev/null +++ b/.config/fish/functions/spark.fish @@ -0,0 +1,33 @@ +function spark --description Sparklines + argparse --ignore-unknown --name=spark v/version h/help m/min= M/max= -- $argv || return + + if set --query _flag_version[1] + echo "spark, version 1.1.0" + else if set --query _flag_help[1] + echo "Usage: spark " + echo " stdin | spark" + echo "Options:" + echo " --min= Minimum range" + echo " --max= Maximum range" + echo " -v or --version Print version" + echo " -h or --help Print this help message" + echo "Examples:" + echo " spark 1 1 2 5 14 42" + echo " seq 64 | sort --random-sort | spark" + else if set --query argv[1] + printf "%s\n" $argv | spark --min="$_flag_min" --max="$_flag_max" + else + command awk -v min="$_flag_min" -v max="$_flag_max" ' + { + m = min == "" ? m == "" ? $0 : m > $0 ? $0 : m : min + M = max == "" ? M == "" ? $0 : M < $0 ? $0 : M : max + nums[NR] = $0 + } + END { + n = split("▁ ▂ ▃ ▄ ▅ ▆ ▇ █", sparks, " ") - 1 + while (++i <= NR) + printf("%s", sparks[(M == m) ? 3 : sprintf("%.f", (1 + (nums[i] - m) * n / (M - m)))]) + } + ' && echo + end +end -- cgit v1.2.3