dotfiles

configuration files for shell, text editor, graphical environment, etc.
git clone git://src.adamsgaard.dk/dotfiles
Log | Files | Refs | README | LICENSE Back to index

commit a047c1b1788280b4ddfa4cf4e5eb5551e604d3e5
parent f5c918ce2641de2c579ad311344b440fc53db087
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date:   Mon,  4 Mar 2019 19:46:38 +0100

Add substitution and error checking

Diffstat:
Mlinks/bin/colortheme | 105++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 102 insertions(+), 3 deletions(-)

diff --git a/links/bin/colortheme b/links/bin/colortheme @@ -31,14 +31,113 @@ function show_themes { echo "${themes[@]}" } -function set_colors { +function get_theme_color { + ! [ -f $path ] && die "Error: Could not find $path" + grep --ignore-case "^\*$1:" $path | awk '{ print $2 }' +} + +function report_colors { + echo "foreground: $foreground" + echo "background: $background" + echo "color0: $color0" + echo "color1: $color1" + echo "color2: $color2" + echo "color3: $color3" + echo "color4: $color4" + echo "color5: $color5" + echo "color6: $color6" + echo "color7: $color7" + echo "color8: $color8" + echo "color9: $color9" + echo "color10: $color10" + echo "color11: $color11" + echo "color12: $color12" + echo "color13: $color13" + echo "color14: $color14" + echo "color15: $color15" +} + +function get_colors { path="$themedir/$1" ! [ -f $path ] && die "Error: Could not find $path" - echo "setting $path" + foreground=$(get_theme_color foreground) + background=$(get_theme_color background) + color0=$(get_theme_color color0) + color1=$(get_theme_color color1) + color2=$(get_theme_color color2) + color3=$(get_theme_color color3) + color4=$(get_theme_color color4) + color5=$(get_theme_color color5) + color6=$(get_theme_color color6) + color7=$(get_theme_color color7) + color8=$(get_theme_color color8) + color9=$(get_theme_color color9) + color10=$(get_theme_color color10) + color11=$(get_theme_color color11) + color12=$(get_theme_color color12) + color13=$(get_theme_color color13) + color14=$(get_theme_color color14) + color15=$(get_theme_color color15) + + if [[ $foreground == "" || $background == "" || $color0 == "" || \ + $color1 == "" || $color2 == "" || $color3 == "" || $color4 == "" || \ + $color5 == "" || $color6 == "" || $color7 == "" || $color8 == "" || \ + $color9 == "" || $color10 == "" || $color11 == "" || $color12 == "" || \ + $color13 == "" || $color14 == "" || $color15 == "" ]]; then + + report_colors + die 'Error: One or more colors were not defined' + fi +} + +function set_colors { + get_colors "$1" + if [ -f ~/.Xresources ]; then + sed -i "s/^\*.foreground: #.*$/\*.foreground: $foreground/;\ + s/^\*.background: #.*$/\*.background: $background/;\ + s/^\*.color0: #.*$/\*.color0: $color0/;\ + s/^\*.color1: #.*$/\*.color1: $color1/;\ + s/^\*.color2: #.*$/\*.color2: $color2/;\ + s/^\*.color3: #.*$/\*.color3: $color3/;\ + s/^\*.color4: #.*$/\*.color4: $color4/;\ + s/^\*.color5: #.*$/\*.color5: $color5/;\ + s/^\*.color6: #.*$/\*.color6: $color6/;\ + s/^\*.color7: #.*$/\*.color7: $color7/;\ + s/^\*.color8: #.*$/\*.color8: $color8/;\ + s/^\*.color9: #.*$/\*.color9: $color9/;\ + s/^\*.color10: #.*$/\*.color10: $color10/;\ + s/^\*.color11: #.*$/\*.color11: $color11/;\ + s/^\*.color12: #.*$/\*.color12: $color12/;\ + s/^\*.color13: #.*$/\*.color13: $color13/;\ + s/^\*.color14: #.*$/\*.color14: $color14/;\ + s/^\*.color15: #.*$/\*.color15: $color15/;\ + s/^\*.color16: #.*$/\*.color16: $color16/" ~/.Xresources + xrdb -merge ~/.Xresources + fi + if [ -f ~/code/st/config.h ]; then + sed -i "s/^\*.foreground: #.*$/\*.foreground: $foreground/" ~/code/st/config.h + sed -i "s/^\*.background: #.*$/\*.background: $background/" ~/code/st/config.h + sed -i "s/^\*.color0: #.*$/\*.color0: $color0/" ~/code/st/config.h + sed -i "s/^\*.color1: #.*$/\*.color1: $color1/" ~/code/st/config.h + sed -i "s/^\*.color2: #.*$/\*.color2: $color2/" ~/code/st/config.h + sed -i "s/^\*.color3: #.*$/\*.color3: $color3/" ~/code/st/config.h + sed -i "s/^\*.color4: #.*$/\*.color4: $color4/" ~/code/st/config.h + sed -i "s/^\*.color5: #.*$/\*.color5: $color5/" ~/code/st/config.h + sed -i "s/^\*.color6: #.*$/\*.color6: $color6/" ~/code/st/config.h + sed -i "s/^\*.color7: #.*$/\*.color7: $color7/" ~/code/st/config.h + sed -i "s/^\*.color8: #.*$/\*.color8: $color8/" ~/code/st/config.h + sed -i "s/^\*.color9: #.*$/\*.color9: $color9/" ~/code/st/config.h + sed -i "s/^\*.color10: #.*$/\*.color10: $color10/" ~/code/st/config.h + sed -i "s/^\*.color11: #.*$/\*.color11: $color11/" ~/code/st/config.h + sed -i "s/^\*.color12: #.*$/\*.color12: $color12/" ~/code/st/config.h + sed -i "s/^\*.color13: #.*$/\*.color13: $color13/" ~/code/st/config.h + sed -i "s/^\*.color14: #.*$/\*.color14: $color14/" ~/code/st/config.h + sed -i "s/^\*.color15: #.*$/\*.color15: $color15/" ~/code/st/config.h + sed -i "s/^\*.color16: #.*$/\*.color16: $color16/" ~/code/st/config.h + fi - xrdb -merge ~/.Xresources } [[ $# -lt 1 ]] && (show_help && exit 1)