dot

packages and services management
Log | Files | Refs | README

commit 9ea3fecce8159a14e9db027d7e77d1600ad7b583
parent 22d042670c0fcf8e5ef1ab97d26a15544d803d47
Author: Josuah Demangeon <mail@josuah.net>
Date:   Fri, 17 Nov 2017 23:15:25 +0100

added forgotten scripts

Diffstat:
Abin/blawk | 50++++++++++++++++++++++++++++++++++++++++++++++++++
Abin/drawk | 46++++++++++++++++++++++++++++++++++++++++++++++
Mbin/http | 3+++
3 files changed, 99 insertions(+), 0 deletions(-)

diff --git a/bin/blawk b/bin/blawk @@ -0,0 +1,49 @@ +#!/bin/awk -f +# ▌ ▜ ▌ +# ▛▌▐ ▀▌▌▌▌▙▘ +# ▙▌▐▖█▌▚▚▘▛▖ - Draw an image using block characters and ImageMagick +#=============================================================================== + +# USAGE: +# blawk [columns lines] file [imagemagick_arguments] + +BEGIN { + if (ARGC <= 3) { + convert = "convert "ARGV[1]" -compress none "ARGV[2] \ + " pbm:- | sed -e 's/ //g' -ne '3,$ p'"; + } else { + convert = "convert "ARGV[3]" -compress none "ARGV[4] \ + " -resize "ARGV[1] * 2"x"ARGV[2] * 4 \ + " pbm:- | sed -e 's/ //g' -ne '3,$ p'"; + } + + + # Character number in a binary pattern from top left to bottom right + chmap[0] = 0x0020; chmap[1] = 0x2598; + chmap[2] = 0x259d; chmap[3] = 0x2580; + chmap[4] = 0x2596; chmap[5] = 0x258c; + chmap[6] = 0x259e; chmap[7] = 0x259b; + chmap[8] = 0x2597; chmap[9] = 0x259a; + chmap[10] = 0x2590; chmap[11] = 0x259c; + chmap[12] = 0x2584; chmap[13] = 0x2599; + chmap[14] = 0x259f; chmap[15] = 0x2588; + + while ((convert | getline) > 0 ) { + + # Get lines by group of 2 + line[1] = $0; + # Skip three lines to keep the aspect ratio + convert | getline; convert | getline; convert | getline; + line[2] = $0; + + for (i = 1; 2 * i < length(line[1]); i++) { + printf("%c", chmap[ \ + 1 * substr(line[1], 2 * i , 1) \ + + 2 * substr(line[1], 2 * i + 1, 1) \ + + 4 * substr(line[2], 2 * i , 1) \ + + 8 * substr(line[2], 2 * i + 1, 1) \ + ]); + } + print "" + } +}+ \ No newline at end of file diff --git a/bin/drawk b/bin/drawk @@ -0,0 +1,45 @@ +#!/bin/awk -f +# ▌ ▌ +# ▛▌▛▘▀▌▌▌▌▙▘ +# ▙▌▌ █▌▚▚▘▛▖ - Drawille implementation in awk (just for image conversions). +#=============================================================================== + +# USAGE: +# blawk [columns lines] file [imagemagick_arguments] + +BEGIN { + if (ARGC <= 3) { + convert = "convert "ARGV[1]" -compress none "ARGV[2] \ + " pbm:- | sed -e 's/ //g' -ne '3,$ p'"; + } else { + convert = "convert "ARGV[3]" -compress none "ARGV[4] \ + " -resize "ARGV[1] * 2"x"ARGV[2] * 4 \ + " pbm:- | sed -e 's/ //g' -ne '3,$ p'"; + } + + while ((convert | getline) > 0 ) { + + # Get lines by group of 4 + line[1] = $0; + convert | getline; line[2] = $0; + convert | getline; line[3] = $0; + convert | getline; line[4] = $0; + + # For each character to be drawn + for (i = 0; 2 * i < length(line[1]); i++) { + # Char number = initial offset + + # Sum of characters offsets * 0 or 1 on the grid + printf("%c", 10240 \ + + 1 * substr(line[1], 2 * i , 1) \ + + 8 * substr(line[1], 2 * i + 1, 1) \ + + 2 * substr(line[2], 2 * i , 1) \ + + 16 * substr(line[2], 2 * i + 1, 1) \ + + 4 * substr(line[3], 2 * i , 1) \ + + 32 * substr(line[3], 2 * i + 1, 1) \ + + 64 * substr(line[4], 2 * i , 1) \ + + 128 * substr(line[4], 2 * i + 1, 1)); + } + print "" + } + close(cmd) +}+ \ No newline at end of file diff --git a/bin/http b/bin/http @@ -14,6 +14,9 @@ case $1 in (wttr) curl wttr.in ;; +(sprunge) + curl -F 'sprunge=<-' http://sprunge.us + ;; (*) printf 'usage: %s ip | ix | w1r3 | wttr [< data]\n' "${0##*/}" ;;