colortheme (6189B)
1 #!/bin/sh 2 set -e 3 4 version="0.1.0" 5 slroot=~/.local/lib 6 7 die() { 8 printf '%s \n' "$1" >&2 9 exit 1 10 } 11 12 show_help() { 13 echo "usage: ${0##*/} [OPTION] THEMEFILE" 14 echo "Writes colors from THEMEFILE to:" 15 echo " ~/.Xresources" 16 echo " $slroot/st/config.h" 17 echo " $slroot/tabbed/config.h" 18 echo " $slroot/dwm/config.h" 19 echo "Valid OPTIONS are:" 20 echo " -h, --help show this message" 21 echo " -v, --version show version information" 22 } 23 24 show_version() { 25 echo "${0##*/} version $version" 26 echo "Licensed under GNU Public License v3+" 27 echo "Written by Anders Damsgaard <anders@adamsgaard.dk>" 28 } 29 30 get_theme_color() { 31 ! [ -f "$path" ] && die "Error: Could not find $path" 32 grep --ignore-case "^\*\.*$1:" "$path" | awk '{ print $2 }' 33 } 34 35 report_colors() { 36 echo "foreground: $foreground" 37 echo "background: $background" 38 echo "color0: $color0" 39 echo "color1: $color1" 40 echo "color2: $color2" 41 echo "color3: $color3" 42 echo "color4: $color4" 43 echo "color5: $color5" 44 echo "color6: $color6" 45 echo "color7: $color7" 46 echo "color8: $color8" 47 echo "color9: $color9" 48 echo "color10: $color10" 49 echo "color11: $color11" 50 echo "color12: $color12" 51 echo "color13: $color13" 52 echo "color14: $color14" 53 echo "color15: $color15" 54 echo "cursorColor: $cursorColor" 55 } 56 57 get_colors() { 58 path="$1" 59 ! [ -f "$path" ] && die "Error: Could not find $path" 60 foreground=$(get_theme_color foreground) 61 background=$(get_theme_color background) 62 color0=$(get_theme_color color0) 63 color1=$(get_theme_color color1) 64 color2=$(get_theme_color color2) 65 color3=$(get_theme_color color3) 66 color4=$(get_theme_color color4) 67 color5=$(get_theme_color color5) 68 color6=$(get_theme_color color6) 69 color7=$(get_theme_color color7) 70 color8=$(get_theme_color color8) 71 color9=$(get_theme_color color9) 72 color10=$(get_theme_color color10) 73 color11=$(get_theme_color color11) 74 color12=$(get_theme_color color12) 75 color13=$(get_theme_color color13) 76 color14=$(get_theme_color color14) 77 color15=$(get_theme_color color15) 78 cursorColor=$(get_theme_color cursorColor) 79 cursorColor=${cursorColor:-#FF00FF} 80 81 if [ "$foreground" = "" ] || \ 82 [ "$background" = "" ] || \ 83 [ "$color0" = "" ] || \ 84 [ "$color1" = "" ] || \ 85 [ "$color2" = "" ] || \ 86 [ "$color3" = "" ] || \ 87 [ "$color4" = "" ] || \ 88 [ "$color5" = "" ] || \ 89 [ "$color6" = "" ] || \ 90 [ "$color7" = "" ] || \ 91 [ "$color8" = "" ] || \ 92 [ "$color9" = "" ] || \ 93 [ "$color10" = "" ] || \ 94 [ "$color11" = "" ] || \ 95 [ "$color12" = "" ] || \ 96 [ "$color13" = "" ] || \ 97 [ "$color14" = "" ] || \ 98 [ "$color15" = "" ] || \ 99 [ "$cursorColor" = "" ]; then 100 101 report_colors 102 die 'Error: One or more colors were not defined' 103 fi 104 } 105 106 set_colors() { 107 get_colors "$1" 108 109 if [ -f ~/.Xresources ]; then 110 sed -i "s/^\*\.foreground: .*$/\*.foreground: $foreground/;\ 111 s/^\*\.background: .*$/\*.background: $background/;\ 112 s/^\*\.color0: .*$/\*.color0: $color0/;\ 113 s/^\*\.color1: .*$/\*.color1: $color1/;\ 114 s/^\*\.color2: .*$/\*.color2: $color2/;\ 115 s/^\*\.color3: .*$/\*.color3: $color3/;\ 116 s/^\*\.color4: .*$/\*.color4: $color4/;\ 117 s/^\*\.color5: .*$/\*.color5: $color5/;\ 118 s/^\*\.color6: .*$/\*.color6: $color6/;\ 119 s/^\*\.color7: .*$/\*.color7: $color7/;\ 120 s/^\*\.color8: .*$/\*.color8: $color8/;\ 121 s/^\*\.color9: .*$/\*.color9: $color9/;\ 122 s/^\*\.color10: .*$/\*.color10: $color10/;\ 123 s/^\*\.color11: .*$/\*.color11: $color11/;\ 124 s/^\*\.color12: .*$/\*.color12: $color12/;\ 125 s/^\*\.color13: .*$/\*.color13: $color13/;\ 126 s/^\*\.color14: .*$/\*.color14: $color14/;\ 127 s/^\*\.color15: .*$/\*.color15: $color15/;\ 128 s/^\*\.cursorColor: .*$/\*.cursorColor: $cursorColor/" ~/.Xresources 129 xrdb -merge ~/.Xresources 130 command -v i3-msg >/dev/null 2>&1 && (i3-msg restart || :) 131 command -v wallpaper >/dev/null 2>&1 && (wallpaper || :) 132 fi 133 134 if [ -f $slroot/st/config.h ]; then 135 sed -i "s/^\t\[257\] = \".*\",.*$/\t\[257\] = \"$foreground\",/;\ 136 s/^\t\[256\] = \".*\",.*$/\t\[256\] = \"$background\",/;\ 137 s/^\t\[0\] = \".*\",.*$/\t\[0\] = \"$color0\",/;\ 138 s/^\t\[1\] = \".*\",.*$/\t\[1\] = \"$color1\",/;\ 139 s/^\t\[2\] = \".*\",.*$/\t\[2\] = \"$color2\",/;\ 140 s/^\t\[3\] = \".*\",.*$/\t\[3\] = \"$color3\",/;\ 141 s/^\t\[4\] = \".*\",.*$/\t\[4\] = \"$color4\",/;\ 142 s/^\t\[5\] = \".*\",.*$/\t\[5\] = \"$color5\",/;\ 143 s/^\t\[6\] = \".*\",.*$/\t\[6\] = \"$color6\",/;\ 144 s/^\t\[7\] = \".*\",.*$/\t\[7\] = \"$color7\",/;\ 145 s/^\t\[8\] = \".*\",.*$/\t\[8\] = \"$color8\",/;\ 146 s/^\t\[9\] = \".*\",.*$/\t\[9\] = \"$color9\",/;\ 147 s/^\t\[10\] = \".*\",.*$/\t\[10\] = \"$color10\",/;\ 148 s/^\t\[11\] = \".*\",.*$/\t\[11\] = \"$color11\",/;\ 149 s/^\t\[12\] = \".*\",.*$/\t\[12\] = \"$color12\",/;\ 150 s/^\t\[13\] = \".*\",.*$/\t\[13\] = \"$color13\",/;\ 151 s/^\t\[14\] = \".*\",.*$/\t\[14\] = \"$color14\",/;\ 152 s/^\t\[258\] = \".*\",.*$/\t\[258\] = \"$cursorColor\",/"\ 153 $slroot/st/config.h 154 fi 155 156 if [ -f $slroot/tabbed/config.h ]; then 157 sed -i "s/normbgcolor \+= \".*\";/normbgcolor = \"$background\";/;\ 158 s/normfgcolor \+= \".*\";/normfgcolor = \"$foreground\";/;\ 159 s/selfgcolor \+= \".*\";/selfgcolor = \"$background\";/;\ 160 s/selbgcolor \+= \".*\";/selbgcolor = \"$foreground\";/;\ 161 s/urgbgcolor \+= \".*\";/urgbgcolor = \"$color9\";/;\ 162 s/urgfgcolor \+= \".*\";/urgfgcolor = \"$color0\";/"\ 163 $slroot/tabbed/config.h 164 fi 165 166 167 if [ -f $slroot/dwm/config.h ]; then 168 sed -i "s/col_gray4\[\] *= \".*\";/col_gray4\[\] = \"$background\";/;\ 169 s/col_cyan\[\] *= \".*\";/col_cyan\[\] = \"$color6\";/;\ 170 s/col_gray3\[\] *= \".*\";/col_gray3\[\] = \"$foreground\";/;\ 171 s/col_gray1\[\] *= \".*\";/col_gray1\[\] = \"$background\";/;"\ 172 $slroot/dwm/config.h 173 fi 174 175 } 176 177 [ $# -lt 1 ] && (show_help && exit 1) 178 179 while :; do 180 case "$1" in 181 -h|-\?|--help) 182 show_help 183 exit 0 184 ;; 185 -v|--version) 186 show_version 187 exit 0 188 ;; 189 --) # end all options 190 shift 191 break 192 ;; 193 -?*) 194 die "Error: Unknown option '$1' specified" 195 ;; 196 *) # no more options 197 break 198 esac 199 shift 200 done 201 202 [ $# -lt 1 ] && die 'Error: No THEMEFILE specified' 203 [ $# -gt 1 ] && die 'Error: More than one THEMEFILE specified' 204 205 set_colors "$1"