actually add grabber.sh

This commit is contained in:
slonkazoid 2024-02-10 22:20:01 +03:00
parent aae4907628
commit b36893239f
Signed by untrusted user who does not match committer: slonk
GPG key ID: 9C51F3072F8D11A2

21
shell/bash/grabber.sh Executable file
View file

@ -0,0 +1,21 @@
#!/usr/bin/env bash
set -e
input="${1:?input not set}"
source="${2:?variable source not set}"
css="$(cat "$input")"
IFS=$'\n'
for line in $css; do
_match="$(grep -m 1 -oP '(?<=var\()[^)\s]+(?=\))' <<< "$line" || :)"
if [[ ${_match:+x} == x ]]; then for match in $_match; do
color="$(grep -m 1 -oP "(?<=$match: )[^;\s]+(?=;)(?:\s+)?" "$source" | tail -n1 || :)"
if [[ ${color:+x} == x ]]; then
echo "replacing var($match) with $color" 1>&2
sed -i s/var\("$match"\)/"$color"/g "$input"
else
echo "$match not defined in $source" 1>&2
fi
done; fi
done