*nohtml*

local/bin/wall

   1 #!/bin/bash
   2 
   3 declare -A base16_ashes=( # {{{
   4     [background]='#1c2023' [foreground]='#c7ccd1'
   5     [color0]='#1c2023' [color8]='#747c84'
   6     [color1]='#c7ae95' [color9]='#c7ae95'
   7     [color2]='#95c7ae' [color10]='#95c7ae'
   8     [color3]='#aec795' [color11]='#aec795'
   9     [color4]='#ae95c7' [color12]='#ae95c7'
  10     [color5]='#c795ae' [color13]='#c795ae'
  11     [color6]='#95aec7' [color14]='#95aec7'
  12     [color7]='#c7ccd1' [color15]='#f3f4f5'
  13 ) # }}}
  14 declare -A base16_flat=( # {{{
  15     [background]='#2c3e50' [foreground]='#e0e0e0'
  16     [color0]='#2c3e50' [color8]='#95a5a6'
  17     [color1]='#e74c3c' [color9]='#e74c3c'
  18     [color2]='#2ecc71' [color10]='#2ecc71'
  19     [color3]='#f1c40f' [color11]='#f1c40f'
  20     [color4]='#3498db' [color12]='#3498db'
  21     [color5]='#9b59b6' [color13]='#9b59b6'
  22     [color6]='#1abc9c' [color14]='#1abc9c'
  23     [color7]='#e0e0e0' [color15]='#ecf0f1'
  24 ) # }}}
  25 declare -A base16_gruvbox_medium=( # {{{
  26     [background]='#282828' [foreground]='#d5c4a1'
  27     [color0]='#282828' [color8]='#665c54'
  28     [color1]='#fb4934' [color9]='#fb4934'
  29     [color2]='#b8bb26' [color10]='#b8bb26'
  30     [color3]='#fabd2f' [color11]='#fabd2f'
  31     [color4]='#83a598' [color12]='#83a598'
  32     [color5]='#d3869b' [color13]='#d3869b'
  33     [color6]='#8ec07c' [color14]='#8ec07c'
  34     [color7]='#d5c4a1' [color15]='#fbf1c7'
  35 ) # }}}
  36 declare -A base16_gruvbox_soft=( # {{{
  37     [background]='#32302f' [foreground]='#d5c4a1'
  38     [color0]='#32302f' [color8]='#665c54'
  39     [color1]='#fb4934' [color9]='#fb4934'
  40     [color2]='#b8bb26' [color10]='#b8bb26'
  41     [color3]='#fabd2f' [color11]='#fabd2f'
  42     [color4]='#83a598' [color12]='#83a598'
  43     [color5]='#d3869b' [color13]='#d3869b'
  44     [color6]='#8ec07c' [color14]='#8ec07c'
  45     [color7]='#d5c4a1' [color15]='#fbf1c7'
  46 ) # }}}
  47 declare -A base16_material=( # {{{
  48     [background]='#263238' [foreground]='#eeffff'
  49     [color0]='#263238' [color8]='#546e7a'
  50     [color1]='#f07178' [color9]='#f07178'
  51     [color2]='#c3e88d' [color10]='#c3e88d'
  52     [color3]='#ffcb6b' [color11]='#ffcb6b'
  53     [color4]='#82aaff' [color12]='#82aaff'
  54     [color5]='#c792ea' [color13]='#c792ea'
  55     [color6]='#89ddff' [color14]='#89ddff'
  56     [color7]='#eeffff' [color15]='#eeffff' # [color15]='#ffffff'
  57 ) # }}}
  58 declare -A base16_material_palenight=( # {{{
  59     [background]='#292d3e' [foreground]='#959dcb'
  60     [color0]='#292d3e' [color8]='#676e95'
  61     [color1]='#f07178' [color9]='#f07178'
  62     [color2]='#c3e88d' [color10]='#c3e88d'
  63     [color3]='#ffcb6b' [color11]='#ffcb6b'
  64     [color4]='#82aaff' [color12]='#82aaff'
  65     [color5]='#c792ea' [color13]='#c792ea'
  66     [color6]='#89ddff' [color14]='#89ddff'
  67     [color7]='#959dcb' [color15]='#ffffff'
  68 ) # }}}
  69 declare -A base16_nord=( # {{{
  70     [background]='#2e3440' [foreground]='#e5e9f0'
  71     [color0]='#2e3440' [color8]='#4c566a'
  72     [color1]='#88c0d0' [color9]='#88c0d0'
  73     [color2]='#bf616a' [color10]='#bf616a'
  74     [color3]='#5e81ac' [color11]='#5e81ac'
  75     [color4]='#ebcb8b' [color12]='#ebcb8b'
  76     [color5]='#a3be8c' [color13]='#a3be8c'
  77     [color6]='#d08770' [color14]='#d08770'
  78     [color7]='#e5e9f0' [color15]='#8fbcbb'
  79 ) # }}}
  80 declare -A base16_ocean=( # {{{
  81     [background]='#2b303b' [foreground]='#c0c5ce'
  82     [color0]='#2b303b' [color8]='#65737e'
  83     [color1]='#bf616a' [color9]='#bf616a'
  84     [color2]='#a3be8c' [color10]='#a3be8c'
  85     [color3]='#ebcb8b' [color11]='#ebcb8b'
  86     [color4]='#8fa1b3' [color12]='#8fa1b3'
  87     [color5]='#b48ead' [color13]='#b48ead'
  88     [color6]='#96b5b4' [color14]='#96b5b4'
  89     [color7]='#c0c5ce' [color15]='#eff1f5'
  90 ) # }}}
  91 declare -A base16_porple=( # {{{
  92     [background]='#292c36' [foreground]='#d8d8d8'
  93     [color0]='#292c36' [color8]='#65568a'
  94     [color1]='#f84547' [color9]='#f84547'
  95     [color2]='#95c76f' [color10]='#95c76f'
  96     [color3]='#efa16b' [color11]='#efa16b'
  97     [color4]='#8485ce' [color12]='#8485ce'
  98     [color5]='#b74989' [color13]='#b74989'
  99     [color6]='#64878f' [color14]='#64878f'
 100     [color7]='#d8d8d8' [color15]='#f8f8f8'
 101 ) # }}}
 102 declare -A base16_tomorrow_night=( # {{{
 103     [background]='#1d1f21' [foreground]='#c5c8c6'
 104     [color0]='#1d1f21' [color8]='#969896'
 105     [color1]='#cc6666' [color9]='#cc6666'
 106     [color2]='#b5bd68' [color10]='#b5bd68'
 107     [color3]='#f0c674' [color11]='#f0c674'
 108     [color4]='#81a2be' [color12]='#81a2be'
 109     [color5]='#b294bb' [color13]='#b294bb'
 110     [color6]='#8abeb7' [color14]='#8abeb7'
 111     [color7]='#c5c8c6' [color15]='#ffffff'
 112 ) # }}}
 113 declare -A default=( # {{{
 114     [background]="#222228" [foreground]="#d8dade"
 115     [color0]="#222228" [color8]="#4e4e56" # [color0]="#37373f"
 116     [color1]="#ff5f5f" [color9]="#ff5f5f"
 117     [color2]="#87af5f" [color10]="#87af5f"
 118     [color3]="#d7af87" [color11]="#ffd75f"
 119     [color4]="#5f5fff" [color12]="#afafd7"
 120     [color5]="#d75fff" [color13]="#d75fff"
 121     [color6]="#87d7d7" [color14]="#87d7d6"
 122     [color7]="#a8aaae" [color15]="#d8dade"
 123 ) # }}}
 124 declare -A dkeg_prevail=( # {{{
 125     [background]='#263139' [foreground]='#dac99d'
 126     [color0]='#263139' [color8]='#455867'
 127     [color1]='#f36f62' [color9]='#f36f62'
 128     [color2]='#c5e19c' [color10]='#c5e19c'
 129     [color3]='#ccb478' [color11]='#ccb478'
 130     [color4]='#4c7e89' [color12]='#4c7e89'
 131     [color5]='#814d61' [color13]='#814d61'
 132     [color6]='#79a69d' [color14]='#79a69d'
 133     [color7]='#c4c4b5' [color15]='#dbdbd1'
 134 ) # }}}
 135 declare -A hybrid_material=( # {{{
 136     [background]='#263238' [foreground]='#ffffff'
 137     [color0]='#263238' [color8]='#707880'
 138     [color1]='#cc6666' [color9]='#cc6666'
 139     [color2]='#f0c674' [color10]='#f0c674'
 140     [color3]='#b5bd68' [color11]='#b5bd68'
 141     [color4]='#8abeb7' [color12]='#8abeb7'
 142     [color5]='#81a2be' [color13]='#81a2be'
 143     [color6]='#b294bb' [color14]='#b294bb'
 144     [color7]='#ffffff' [color15]='#ffffff'
 145 ) # }}}
 146 declare -A monokai=( # {{{
 147     [background]='#272822' [foreground]='#f8f8f2'
 148     [color0]='#272822' [color8]='#75715e'
 149     [color1]='#f92672' [color9]='#f92672'
 150     [color2]='#a6e22e' [color10]='#a6e22e'
 151     [color3]='#f4bf75' [color11]='#f4bf75'
 152     [color4]='#66d9ef' [color12]='#66d9ef'
 153     [color5]='#ae81ff' [color13]='#ae81ff'
 154     [color6]='#a1efe4' [color14]='#a1efe4'
 155     [color7]='#f8f8f2' [color15]='#f9f8f5'
 156 ) # }}}
 157 declare -A solarized=( # {{{
 158     [background]='#073642' [foreground]='#fdf6e3'
 159     [color0]='#073642' [color8]='#6c7c80'
 160     [color1]='#dc322f' [color9]='#dc322f'
 161     [color2]='#859900' [color10]='#859900'
 162     [color3]='#b58900' [color11]='#b58900'
 163     [color4]='#268bd2' [color12]='#268bd2'
 164     [color5]='#d33682' [color13]='#d33682'
 165     [color6]='#2aa198' [color14]='#2aa198'
 166     [color7]='#eee8d5' [color15]='#eee8d5'
 167 ) # }}}
 168 declare -A zenburn3=( # {{{
 169     [background]='#3f3f3f' [foreground]='#ffffff'
 170     [color0]='#3f3f3f' [color8]='#828282'
 171     [color1]='#dca5a5' [color9]='#dca5a5'
 172     [color2]='#c0e380' [color10]='#c0e380'
 173     [color3]='#e4e49a' [color11]='#e4e49a'
 174     [color4]='#7d9ec0' [color12]='#7d9ec0'
 175     [color5]='#ffc66d' [color13]='#ffc66d'
 176     [color6]='#8acccf' [color14]='#8acccf'
 177     [color7]='#ffffff' [color15]='#ffffff'
 178 ) # }}}
 179 
 180 [[ -d ~/.config/wall ]] &&
 181 for i in ~/.config/wall/*.sh; do source $i; done
 182 
 183 return 2>&-
 184 
 185 ################################################################################
 186 
 187 declare -n colors=default
 188 source ~/.cache/wall/colors.sh 2>&- &&
 189 for i in {back,fore}ground color{0..15}; do colors[$i]=${!i}; done
 190 
 191 case $1 in
 192     -b|--background)
 193         cp "$2" ~/.config/wallpaper.jpg 2>&-
 194         hsetroot -cover $_
 195 
 196         qdbus --system org.freedesktop.Accounts /org/freedesktop/Accounts/User$UID \
 197         org.freedesktop.DisplayManager.AccountsService.BackgroundFile $_
 198 
 199         exit
 200     ;;
 201 
 202     -c|--color)
 203         reload=1; source $0; declare -n colors=$2 2>&-
 204         list(){ source $0; local | grep -io "^\w*$1\w*"; }
 205         [[ ! $2 || ! ${colors[@]} ]] && { list "$2"; exit; }
 206     ;;
 207 
 208     -r|--reload) reload=1;;
 209 esac
 210 
 211 ################################################################################
 212 
 213 mkdir -p ~/.cache/wall; cd $_
 214 keys1=$(echo {back,fore}ground color{0..15})
 215 keys2=$(echo {back,fore}ground{,_rgba,_argb} color{0..15}{,_rgba,_argb})
 216 print(){ printf "${3:-%s}\n" "$(for i in $1; do printf "${3:+  }$2\n" $i ${colors[$i]}; done)"; }
 217 
 218 [[ ${colors[foreground]} < ${colors[color7]}  ]] && colors[foreground]=${colors[color7]}
 219 [[ ${colors[foreground]} < ${colors[color15]} ]] && colors[foreground]=${colors[color15]}
 220 
 221 for i in $keys1; do
 222     colors[${i}_rgba]="${colors[$i]}e0"
 223     colors[${i}_argb]="#e0${colors[$i]:1}"
 224 done
 225 
 226 > colors.sh   print "$keys2" '%s="%s"'
 227 > colors.xres print "$keys2" '*%s: %s'
 228 > colors.css  print "$keys2" '--%s: %s;' ':root {\n%s\n}'
 229 > colors.gtk  print "$keys1" '@define-color %s %s;'
 230 > colors.rasi print "$keys2" '%s: %s;' '* {\n%s\n}'
 231 > colors.json print "$keys2" '"%s": "%s",' '{\n%s}'
 232 > colors.ini  print "$keys2" '%s = %s' '[colors]\n%s'
 233 > colors.h    print "$keys2" 'char %s[] = "%s";'
 234 > colors.php  print "$keys2" '$%s = "%s";' '<?php\n%s'
 235 
 236 sed -i 's/_/-/' colors.rasi
 237 sed -i 's/,}/\n}/' colors.json
 238 
 239 for i in {0..15}; do printf '\e]P%x%s\a' $i ${colors[color$i]:1}; done > colors-linux
 240 for i in {0..15}; do printf '\e]4;%d;%s\a' $i ${colors[color$i]}; done > colors-xterm
 241 
 242 printf '\e]10;%s\a'    ${colors[foreground]} >> colors-xterm
 243 printf '\e]11;%s\a'    ${colors[background]} >> colors-xterm
 244 printf '\e]12;%s\a'    ${colors[foreground]} >> colors-xterm
 245 printf '\e]4;256;%s\a' ${colors[foreground]} >> colors-xterm
 246 
 247 ################################################################################
 248 
 249 printf '\e[1;30m'
 250 trap 'printf "\e[0m"; colors' EXIT
 251 
 252 xrdb -merge colors.xres
 253 $0 -b ${colors[wallpaper]:-~/.config/wallpaper.jpg}
 254 
 255 [[ $reload ]] || exit
 256 
 257 dunster; i3 restart; imwheel -k
 258 for i in dwm awesome; do pkill -HUP -x $i; done
 259 for i in /dev/pts/[0-9]; do cat colors-xterm > $i; done
 260 for i in /dev/tty[0-9];  do cat colors-linux > $i; done 2>&-
 261 for i in sxhkd compton picom polybar; do pkill -USR1 -x $i && sleep 0.1; done