shchemes/lib/apply_scheme_to_template.sh

61 lines
898 B
Bash

#!/usr/bin/env bash
SCHEME=$1
TEMPLATE=$2
if [ -z "$MO_PATH" ]; then
MO_PATH="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")/mo/mo"
fi
source $MO_PATH
rgb_r() {
printf "$((0x${MO_FUNCTION_ARGS[0]:0:2}))"
}
rgb_g() {
printf "$((0x${MO_FUNCTION_ARGS[0]:2:2}))"
}
rgb_b() {
printf "$((0x${MO_FUNCTION_ARGS[0]:4:4}))"
}
rgb() {
rgb_r; printf " "
rgb_g; printf " "
rgb_b; printf " "
}
clamp() {
if [[ $1 -lt 0 ]]; then
printf "0"
else
if [[ $1 -gt 255 ]]; then
printf "255"
else
printf "%s" "$1"
fi
fi
}
lighten() {
mod="${MO_FUNCTION_ARGS[1]}"
parts=("$(rgb_r)" "$(rgb_g)" "$(rgb_b)")
vars=""
for part in "${parts[@]}"; do
let var=$part+$mod
vars=$vars"$(clamp "$var") "
done
printf "%02x%02x%02x" $vars
}
darken() {
MO_FUNCTION_ARGS[1]="-${MO_FUNCTION_ARGS[1]}"
lighten
}
set -a # All variables after this will be exported
source $SCHEME
mo "$TEMPLATE"