#!/bin/sh

path=$(dirname "$(readlink -f "$0")")
. "$path"/../.utils/apply-color-parse-arg

file="$path"/fuzzel.ini
entries="match selection-match border"

if pgrep -x "fuzzel" -u "$USER" > /dev/null; then
    pkill -x fuzzel || log_error "Failed to kill fuzzel process"
    # and move on
fi

for entry in $entries; do
    # Not very sure if alpha channels are neccessary here, but just in case
    sed -i -E "s/^($entry\s*=\s*)([0-9A-Fa-f]{6})([0-9A-Fa-f]{0,2})/\1${colorHex}\3/" "$file" || {
        log_error "Failed to edit ${file} for entry ${entry}"
        exit 1
    }
done

log_success "fuzzel"