small pixel drawing of a pufferfish dotfiles

remove complex scripties
j3s j3s@c3f.net
Fri, 16 Oct 2020 20:43:13 -0500
commit

a08a1610bc87a8e27aa3750bfaf3f8842ca6f6ef

parent

b7e670620bec74e25b9c066c82f0ef8cd32d7482

2 files changed, 0 insertions(+), 211 deletions(-)

jump to
D bin/bud

@@ -1,110 +0,0 @@

-#!/bin/sh -f -# -# pywalesque posix sh alternative. - -img() { - [ -d "$1" ] && { - set +f - set -f -- "$1/"* - int="$(shuf -i "1-$#" -n 1)" - shift $(expr $int - 1) - } - - [ -f "${img:=$1}" ] || exit 1 - - printf '%s\n' "$img" -} - -hex2rgb() { - set -- "${1##\#}" - - r=${1%%????} - g=${1##??} - g=${g%%??} - b=${1##????} - - r=$((0x$r)) - g=$((0x$g)) - b=$((0x$b)) -} - -mod() { - hex2rgb "$2" - - # The operator is stored in a variable - # which makes shellcheck freak out. - # shellcheck disable=1102,2086 - { - r=$((r $3 $4)) - g=$((g $3 $4)) - b=$((b $3 $4)) - } - - r=$((r > 255 ? 255 : r < 0 ? 0 : r)) - g=$((g > 255 ? 255 : g < 0 ? 0 : g)) - b=$((b > 255 ? 255 : b < 0 ? 0 : b)) - - export "$1=$(printf '%02x%02x%02x' "$r" "$g" "$b")" -} - -col() { - cache_file=$(printf %s "$img" | base64) - - # Backticks need to be used here to fix bugs in - # some specific POSIX shells. - # - # Word splitting is also intentional and safe here. - # shellcheck disable=2046,2006 - if [ -f "$cache_dir/$cache_file" ]; then - paleta < "$cache_dir/$cache_file" & - - else - set -- `\ - convert "$img" \ - -alpha off \ - -resize 64x64 \ - -posterize 16 \ - -fill white \ - -colorize 30% \ - -modulate 125,175,100 \ - -unique-colors \ - txt:- | - while IFS='# ' read -r _ _ col _; do - i=$((i+1)) - [ "$i" -lt 11 ] && continue - [ "$i" -gt 16 ] && continue - printf '%s\n' "$col" - done - ` - - # These variables are dynamically defined, - # ignore undeclared variable warnings. - # shellcheck disable=2154 - { - mod bg "$2" / 4 - mod fg "$2" + 150 - mod co "$bg" + 125 - - set -- "$bg" "$@" "$fg" "$co" "$@" "$fg" - } - - printf '%s\n' "$@" | paleta & - printf '%s\n' "$@" > "$cache_dir/$cache_file" - fi -} - -main() { - mkdir -p "${cache_dir:=${XDG_CACHE_HOME:=${HOME}/.cache}/bud}" - - img "$1" - - display \ - -page 3200x \ - -sample 3200x \ - -window root \ - "$img" & - - col & -} - -main "$1"
D bin/paleta

@@ -1,101 +0,0 @@

-#!/usr/bin/env bash -# -# paleta - change terminal colors on the fly. - -read_input() { - [[ $1 == -v ]] && { - printf 'paleta 1.0.0\n' - exit - } - - [[ $1 == -r ]] && { - load_sequences - exit - } - - # Input from space separated arguments. - [[ $1 ]] && { - input=("$@") - - # Input from single string. - ((${#input[@]} == 1 && ${#input[0]} > 7)) && - read -ra input <<< "${input[*]}" - - # Input from file argument. - (($# == 1)) && [[ -f $1 ]] && - IFS=$'\n ' read -d "" -ra input < "$1" - } - - # Input from stdin. - [[ $1 ]] || IFS=$'\n ' read -d "" -ra input </dev/stdin - - [[ $* == *-* || -z $1 && -z ${input[0]} ]] && { - printf 'usage: paleta -r, paleta [colors], paleta file\n' - printf ' - [colors] a space separated list of hex colors.\n' - exit 1 - } -} - -parse_colors() { - ((${#input[@]} > 16)) && - printf 'warn: Too many colors specified, ignoring past 16th.\n' >&2 - - ((${#input[@]} < 16)) && - printf 'warn: Too few colors given, repeating last color.\n' >&2 - - for ((i=0; i<16; i++)); { - [[ ${input[i]:-000000} =~ ^#?[a-fA-F0-9]{6}$ ]] || { - printf '%s\n' "error: Color [$((i+1))] isn't a valid hex color." >&2 - exit 1 - } - - # Use the last defined color for all colors if less than - # 16 colors were given as input. - colors[i]=${input[i]:-${input[-1]}} - colors[i]=\#${colors[i]//\#} - } -} - -make_sequences() { - # Colors 0-15. - for ((i=0;i<${#colors[@]};i++)) { - sequences+="]4;${i};${colors[i]}\\" - } - - # 10: Foreground color, - # 11: Background color, - # 12: Cursor Foreground color. - # Source: https://goo.gl/KcoQgP - sequences+="]10;${colors[15]}\\" - sequences+="]11;${colors[0]}\\" - sequences+="]12;${colors[15]}\\" - - # Border Background color (URxvt). - # (VTE doesn't handle unknown sequences very well. - # Skip this sequence if running in VTE.) - [[ $VTE_VERSION ]] || sequences+="]708;${colors[0]}\\" -} - -send_sequences() { - for tty in /dev/pts/[0-9]*; do - [[ -w $tty ]] && printf %b "$sequences" > "$tty" & - done - - printf %b "$sequences" > "$cache_dir/colors" -} - -load_sequences() { - [[ -f $cache_dir/colors ]] && - printf %b "$(< "${cache_dir}/colors")" -} - -main() { - mkdir -p "${cache_dir:=${XDG_CACHE_HOME:=${HOME}/.cache}/paleta}" - - read_input "$@" - parse_colors - make_sequences - send_sequences & -} - -main "$@"