From b36893239f2c8f01b5262a1d92ea85abaabe3b7c Mon Sep 17 00:00:00 2001 From: slonkazoid Date: Sat, 10 Feb 2024 22:20:01 +0300 Subject: [PATCH] actually add grabber.sh --- shell/bash/grabber.sh | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100755 shell/bash/grabber.sh diff --git a/shell/bash/grabber.sh b/shell/bash/grabber.sh new file mode 100755 index 0000000..adb189d --- /dev/null +++ b/shell/bash/grabber.sh @@ -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