wms/wms_mimic.sh
2023-09-26 01:25:05 -03:00

32 lines
1 KiB
Bash
Executable file

#!/bin/sh
TARGET=$1 # image target
TMPCOL="/tmp/tmpcol" # path to the extracted colors file
WMVAR="$HOME/.config/wms/wms_var" # window manager variables
NC="3" # number of colors to extract
# color extractor
colext() {
convert $TARGET -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 "$TARGET" ]; 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/" $WMVAR # new acive color
sed -i "s/^.*\bIC=\b.*$/IC=$ic/" $WMVAR # new inactive color
sed -i "s/^.*\bBC=\b.*$/BC=$bc/" $WMVAR # new background color
# apply the change
wms_value.sh -d
wms_mainrole.sh -t
fi
fi