From ebc7e8adfe16bf509f7e6e31df7f33e97d414099 Mon Sep 17 00:00:00 2001 From: WhatTheMike Date: Tue, 26 Apr 2022 11:03:12 -0400 Subject: [PATCH] added rainbow --- bash/rainbow | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100755 bash/rainbow diff --git a/bash/rainbow b/bash/rainbow new file mode 100755 index 0000000..17a4457 --- /dev/null +++ b/bash/rainbow @@ -0,0 +1,34 @@ +#!/bin/bash +# ASCII blocks: █▓▒░ +block="░" +[ -z "$1" ] && c="$block" || c="$1" +[ -z "$2" ] && prompt="pi@blueberrypielol" || prompt="$2" +[[ "$@" == *"--raw"* ]] && praw=1 +colors=18 +chars=${#prompt} +let short=$chars/$colors # min length +let full="chars%colors" +let part="$colors-($chars%$colors)" # short color count +let nmax="$chars%$colors" # Long color count +[ $nmax -eq 0 ] && max=$short || let max=$short+1 # max length +pos=0 +p=0 +[[ "$c" == "b" ]] && c="$block" +for i in 196 202 214 220 226 190 154 118 85 87 39 33 27 63 99 135 171 207; do + if [[ "$c" == "n" ]]; then + pretty="${pretty}\e[38;5;${i}m${i}\e[0m " + elif [[ "$c" == "p" ]]; then + [ ${pos} -lt ${full} ] && len=$max || len=$short + #${parameter:offset:length} + pretty="${pretty}\e[38;5;${i}m${prompt:${p}:${len}}\e[0m" + let p=p+len + let pos=pos+1 + else + pretty="${pretty}\e[38;5;${i}m${c}\e[0m" + fi +done +echo +[ -z "$pretty" ] || echo -e $pretty +[ -z "$praw" ] || echo +[ -z "$praw" ] || echo $pretty +echo