dot

packages and services management
Log | Files | Refs | README

commit 6736d69bf700844730c48431744f5585d653b4f6
parent a325010ac0924c876ce83641004e4d2f11eaecd3
Author: josuah <mail@josuah.net>
Date:   Mon, 19 Dec 2016 09:57:32 +0000

Simplified and made shellcheck happy

Diffstat:
M.local/bin/tty-theme | 69++++++++++++++++++++++++++++++++++++++-------------------------------
1 file changed, 38 insertions(+), 31 deletions(-)

diff --git a/.local/bin/tty-theme b/.local/bin/tty-theme @@ -1,3 +1,4 @@ +#!/bin/sh # Set the theme for the tty from a simple file format # normal bold @@ -273,45 +274,51 @@ F ffffff ' -show=0 -while read -r color hex -do - if [ "$hex" ] - then - themes="$themes\033]P$color$hex" - show=1 - elif [ "$color" ] - then - name="$color" - elif [ "$show" -eq 1 ] - then - i=$((i + 1)) - - themes="$themes\033[K " - for c in 0 1 2 3 4 5 6 7 - do - themes="$themes \033[3${c}m___\033[1m___\033[m" - done - themes="$themes\r $name\r $i\n\033[K\n" - - show=0 - fi -done << EOF +theme() +{ + local number="$1" show=0 i=0 + + printf '\033[H\033[J' + + while read -r color hex + do + if [ "$hex" ] + then + printf '\033]P%s%s' "$color" "$hex" + show=1 + elif [ "$color" ] + then + name="$color" + elif [ "$show" -eq 1 ] + then + i=$((i + 1)) + + printf '\033[K%3s %-20s' "$i" "$name" + for c in 0 1 2 3 4 5 6 7 + do + printf ' \033[3%sm___\033[1m___\033[m' "$c" + done + printf '\n\033[K\n' + + show=0 + fi + + [ "$number" ] && [ "$i" -ge "$number" ] && return 0 + done << EOF $THEMES EOF +} if [ -z "$1" ] then - printf "\033[H\033[J$themes\033]P0000000\033]P7aaaaaa\033[J\n" - read -p "Enter the number of a theme: " number + theme + printf '\033]P0000000\033]P7aaaaaa\033[J\n Theme number: ' + read number else number="$1" fi -printf '\033[%s;0H\033[J' "$((number * 2 - 1))" - -printf "$themes" | cut -d ' -' -f "$((number * 2 - 1))" -printf '\033[J\n' +theme "$number" +printf '\033[J'