dotfiles

My personal shell configs and stuff
git clone git://git.alex.balgavy.eu/dotfiles.git
Log | Files | Refs | Submodules | README | LICENSE

commit bb4100e2a95cf5c8723c5eed13acfd9cedef55e1
parent 2174fb5e346168402a9868db829a9c7dcce63a64
Author: Alex Balgavy <alex@balgavy.eu>
Date:   Fri,  7 May 2021 12:38:26 +0200

print-colors: rename & make POSIX compatible

Diffstat:
Ascripts/print-colors | 18++++++++++++++++++
Dscripts/tput-colors | 25-------------------------
2 files changed, 18 insertions(+), 25 deletions(-)

diff --git a/scripts/print-colors b/scripts/print-colors @@ -0,0 +1,18 @@ +#!/bin/sh +die() { printf '%s\n' "$1" >&2 && exit 1; } + +command -v tput > /dev/null 2>&1 || die "tput not installed." + +[ -z "$(printf '%s' "$1" | tr -d '0-9')" ] || die 'Usage: tput-colors [number]' +# Print out 16 colors by default +[ "$#" -eq 0 ] && set -- 16 + +tput init >/dev/null 2>&1 + +: $((i=0)) +while [ $((i < $1)) -ne 0 ]; do + case $i in 0) pref="(black)";; 1) pref="(red)";; 2) pref="(green)";; 3) pref="(yellow)";; 4) pref="(blue)";; 5) pref="(magenta)";; 6) pref="(cyan)";; 7) pref="(white)";; *) pref="";; esac + echo "$(tput sgr0)$i$pref $(tput setaf "$i")sample text" + i=$((i+1)) +done + diff --git a/scripts/tput-colors b/scripts/tput-colors @@ -1,25 +0,0 @@ -#!/usr/bin/env bash -if ! command -v tput &> /dev/null; then - echo "tput not installed." - exit 1 -fi - -if ! [[ "$1" =~ ^[0-9]+$ ]]; then - echo "Usage: tput-colors [number]" - exit 1 -fi -tput init &> /dev/null -hr() { tput sgr0; for ((i=0; i<$(tput cols); i++)); do echo -n "#"; done; echo; } -hr -echo "Colors for tput:" -hr -if [ $# -eq 0 ]; then - for ((i=1; i<=$(tput colors); i++)); do - echo "$(tput sgr0)$i $(tput setaf $i)sample text" - done -else - for ((i=1; i<=$1; i++)); do - echo "$(tput sgr0)$i $(tput setaf $i)sample text" - done -fi -hr