wms/wms_mimic.sh

42 lines
1.4 KiB
Bash
Executable file

#!/bin/sh
TMPIMG="/tmp/mimic.png" # temp image target
TMPCOL="/tmp/tmpcol" # temp extracted colors file
WMSVAR="$HOME/.config/wms/wms_var" # window manager variables
XVAR="$HOME/.Xresources" # default x variable file
NC="3" # number of colors to extract
# spy on what's on the desktop
import -w root $TMPIMG
# color extractor
colext() {
convert $TMPIMG -colors $NC -depth 6 -format '%c' -alpha off histogram:info:- | awk -v RS="" '{print $11,$7,$3}' | tr -d '#'
}
# if the image file exists, extract the colors and store them temporarily
if [ -f "$TMPIMG" ]; then
colext > $TMPCOL
# check if N colors have been extracted
if [ "$(wc -w < $TMPCOL)" = "$NC" ]; then
# load extracted colors into variables
read ac ic bc < $TMPCOL
# overwrite the values in ~/.config/wms/wms_var
sed -i "s/^.*\bAC=\b.*$/AC=$ac/" $WMSVAR # new acive color
sed -i "s/^.*\bIC=\b.*$/IC=$ic/" $WMSVAR # new inactive color
sed -i "s/^.*\bBC=\b.*$/BC=$bc/" $WMSVAR # new background color
# overwrite the xterm, emacs and nsxiv values in ~/.Xresources
sed -i "s/\(XTerm\*background:\).*/\XTerm\*background: \#$bc/" $XVAR
sed -i "s/\(Nsxiv\*window.background:\).*/\Nsxiv\*window.background: \#$bc/" $XVAR
# apply the change
wms_value.sh -d
wms_mainrole.sh -t
xrdb -merge $XVAR
fi
fi