084e6fb9ca
- Add comprehensive `--description` flags to all fish functions for better `help` and `functions` output. - Introduce and correct `--wraps` flags to ensure proper completions for aliased commands (e.g., `top` wrapping `btop`, `zellij`, `upgrade` wrapping `paru`). - Prepend descriptive comments before function definitions for better source readability. - Add standard copyright and SPDX license identifiers to shell scripts. - Enhance script robustness by ensuring consistent terminal checks (Kitty, WezTerm) and graceful fallbacks in window/tab spawning functions (`spwin`, `tab`). - Implement graceful fallbacks to basic core utilities when preferred modern alternatives are missing (e.g., `top` falling back to system `top` if `btop` is missing, `view` falling back to `less` or `cat` if `nvim` is unavailable). - Improve overall code consistency across the `functions/` directory.
38 lines
1.4 KiB
Fish
38 lines
1.4 KiB
Fish
# Copyright (C) 2026 Rootiest
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
# Sparklines
|
|
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 <numbers ...>"
|
|
echo " stdin | spark"
|
|
echo "Options:"
|
|
echo " --min=<number> Minimum range"
|
|
echo " --max=<number> 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
|