You are not logged in.

#1 2014-05-14 12:30:42

hughitt1
Member
Registered: 2010-02-18
Posts: 82
Website

[script] colortest - load term colors from an Xresources, etc. file

Hi all,

This has probably already been done, but I couldn't find anything similar so I though I would share it just in case...

Just a quick and dirty script to load term color settings from a Xresources-like file containing "color: xx" settings. So far only tested with ZSH and URxvt.

It just provides a lazy alternative to using 'xrdb -merge xxx' and opening a new console each time you want to try out a new theme.

Example usage:

$ colortest ~/.termcolors/theme1

Github: https://github.com/khughitt/dotfiles/tr … /colortest

Cheers,
Keith

#
# Sets the term colors to those specified in a .Xresources, etc. file
# for testing new color themes.
#
# Keith 2014/05/14
# https://github.com/khughitt/dotfiles/tree/master/bin/colortest
#

# if a file was specified, attempt parse colors and set terminal to those
# colors
if [ -n "$1" ]; then
    infile=$1
    echo 'Loading colors from ${infile}...'

    function setColor() {
        color=$1

        # get hex color from file
        hex=$(grep "color${color} *:" $infile | grep -v "^\!" | \
              grep --color='never' -Eo "#[a-zA-Z0-9]{6}")

        # convert to RGB triplet (0-1000)
        red=$(printf "%.0f" $(( $(echo 0x${hex:1:2}) / 255.0 * 1000 )))
        green=$(printf "%.0f" $(( $(echo 0x${hex:3:2}) / 255.0 * 1000 )))
        blue=$(printf "%.0f" $(( $(echo 0x${hex:5:2}) / 255.0 * 1000 )))

        # set color
        tput initc $color $red $green $blue 
    }

    for i in {0..15}; do
        setColor $i
    done
fi

Offline

#2 2014-05-14 22:26:58

Head_on_a_Stick
Member
From: The Wirral
Registered: 2014-02-20
Posts: 8,746
Website

Re: [script] colortest - load term colors from an Xresources, etc. file

If you use .Xdefaults instead of .Xresources, URxvt parses this every time it starts & no "xrdb -merge" is needed wink


Para todos todo, para nosotros nada

Offline

#3 2014-05-17 01:28:01

Saint0fCloud
Member
Registered: 2009-03-31
Posts: 137

Re: [script] colortest - load term colors from an Xresources, etc. file

Wow, I always manage to completely forget about tput. I wrote a similar script in bash that involved quite a bit of painful mucking around with xterm esc sequences (https://gist.github.com/jsks/11323851), but at least it will automatically restore the original theme.

Offline

#4 2014-05-17 22:36:03

abner
Member
Registered: 2013-12-16
Posts: 15

Re: [script] colortest - load term colors from an Xresources, etc. file

Thank you very much for this, I was looking for a way to do exactly this just the other day.

Offline

Board footer

Powered by FluxBB