2023-08-22 07:18:52 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
2023-10-11 20:06:17 +02:00
|
|
|
TARGET=$1 # image target
|
|
|
|
TMPCOL="/tmp/tmpcol" # path to the 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
|
2023-09-26 04:34:52 +02:00
|
|
|
|
|
|
|
# color extractor
|
|
|
|
colext() {
|
2023-09-26 06:25:05 +02:00
|
|
|
convert $TARGET -colors $NC -depth 6 -format '%c' -alpha off histogram:info:- | awk -v RS="" '{print $11,$7,$3}' | tr -d '#'
|
2023-09-26 04:34:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# 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
|
2023-10-11 20:06:17 +02:00
|
|
|
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 term 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
|
2023-09-26 04:34:52 +02:00
|
|
|
|
|
|
|
# apply the change
|
|
|
|
wms_value.sh -d
|
|
|
|
wms_mainrole.sh -t
|
2023-10-11 20:06:17 +02:00
|
|
|
xrdb -merge $XVAR
|
2023-08-22 07:18:52 +02:00
|
|
|
|
|
|
|
fi
|
2023-09-26 04:34:52 +02:00
|
|
|
fi
|