Repository: jorgebucaran/spark.fish Branch: main Commit: 90a60573ec8a Files: 6 Total size: 6.4 KB Directory structure: gitextract_569224k0/ ├── .github/ │ └── workflows/ │ └── ci.yml ├── LICENSE.md ├── README.md ├── completions/ │ └── spark.fish ├── functions/ │ └── spark.fish └── tests/ └── spark.fish ================================================ FILE CONTENTS ================================================ ================================================ FILE: .github/workflows/ci.yml ================================================ name: CI on: push jobs: test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Install Fish run: | sudo apt-add-repository -yn ppa:fish-shell/release-3 sudo apt-get update sudo apt-get install -y fish - name: Install Tools run: | curl -sL https://git.io/fisher | source fisher install jorgebucaran/fishtape $GITHUB_WORKSPACE fishtape tests/*.fish shell: fish {0} ================================================ FILE: LICENSE.md ================================================ Copyright © Jorge Bucaran <> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: README.md ================================================ # spark.fish > Sparklines for [Fish](https://fishshell.com). Unofficial port of [spark.sh](https://github.com/holman/spark) with `--min`, `--max` flags and improved [performance](#performance). ## Installation Install with [Fisher](https://github.com/jorgebucaran/fisher): ```console fisher install jorgebucaran/spark.fish ``` ## Quickstart You want to visualize a range of numbers right in your terminal. ```console $ spark 1 2 4 8 ▁▂▄█ ``` And here is a sequence of random numbers. ```console $ seq 64 | sort --random-sort | spark ▅▄▂▇▂▅▆▄▃█▂▅▄▁▆▆▃█▄▁▇▅▂▃▇▃▃▄▇▄▅▆▇▂▅▁▇▁▄▂▆▅▃█▇▆▆▅▆▃▄▄▇▃▂▇█▅▃█▁▂▂▆ ``` You can set the `--min=` or `--max=` values for your sparkline too. ```console $ 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](https://github.com/holman/spark/wiki/Wicked-Cool-Usage) wiki, ported to Fish. Line lengths. ```console $ awk \$0=length (functions --details spark) | spark ▃▆▃▃▃▄▃▂▄▄▄▅▂▄▅▂▆▁▅▂▅▅▃▂▂▆▃█▂▁▁▁ ``` Number of commits in a repo, by author. ```console $ git shortlog --summary | string match --regex "\d+" | spark █▁▁▁▃▁▁▄▁▁▁ ``` Total run time of processes. ```console $ ps -A | string replace --filter --regex -- ".*(\d+):(\d+).*" "\$1 * 3600 + \$2 * 60" | bc | spark ▇▁▂▁▆▁▂▂▁▃▁▃▁▁▁▆▁▁▁▂▁▃▂▁▁▃▁▁▁▁▁▂▁▁▂▁▁▁▁▁▆▂▃▂▁▂▃▁▆▁▁▁▂▁▁▁▁▃▂▂▁▇▁▁▁▁▆ ``` LOC added per commit over the last week. ```console $ git diff @~7 --numstat | string replace --regex -- "(^\d+).*" "\$1" | spark ▁▁▁▁▁▁▁▁▂▁▁▁▁▁▁▂▂▃█▄▁▁ ``` A moving wave through the terminal. ```fish 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 ``` ```console ▆▄▂▁▂▄▆▇█▇▆▄▂▁▂▄▆▇█▇▆▄▂▁▂▄▆▇█▇▆▄▂▁▂▄▆▇█▇▆▄▂▁▂▄▆▇█▇▆▄▂▁▂▄▆▇█ ``` ## Performance Spark is faster than [`spark.sh`](https://github.com/holman/spark), reading and writing relatively large datasets under milliseconds. ```console $ 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](LICENSE.md) ================================================ FILE: completions/spark.fish ================================================ complete --command spark --exclusive --long min --description "Minimum range" complete --command spark --exclusive --long max --description "Maximum range" complete --command spark --exclusive --long version --description "Print version" complete --command spark --exclusive --long help --description "Print this help message" ================================================ FILE: functions/spark.fish ================================================ 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 ================================================ FILE: tests/spark.fish ================================================ @test "one" (spark 1) = ▃ @test "constant" (spark 5 5) = ▃▃ @test "pyramid" (spark 1 2 3 4 5 6 7 8 7 6 5 4 3 2 1) = ▁▂▃▄▅▆▇█▇▆▅▄▃▂▁ @test "distance" (spark 1 5 10 15 20) = (spark 10 50 100 150 200) @test "upstairs" (spark 990 993 996) = ▁▄█ @test "fedora" (spark -5 3 2 -1 -5) = ▁█▇▄▁ @test "downstairs" (spark -500 -501 -502) = █▄▁ @test "sinewave" (spark 2 -1 -4 -6 -4 -1 2 5 6 5 2 -1 -4 -6 -4 -1 2) = ▆▄▂▁▂▄▆▇█▇▆▄▂▁▂▄▆ @test "stdin" (seq 8 | spark) = ▁▂▃▄▅▆▇█ @test "indefinite" (spark 25 45) = ▁█ @test "definite" (spark 0 25 45) = ▁▅█ @test "25,45 min=0" (spark --min=0 -- 25 45) = ▅█ @test "5,6,7 min=0" (spark --min=0 -- 5 6 7) = ▆▇█ @test "squash" (spark --max=10 -- 1 5 1) = ▁▄▁